service-activator or listener-container - spring-integration

I am using Spring AMQP and Spring Integration. I am currently using a service-activator from integration as my handler. I have tried to get an amqp listener working as well but I never receive the message. Is using a service-activator accepted practice or should I be using a listener?
<!-- Receive Inbound messages and process them -->
<int-amqp:inbound-channel-adapter channel="sda.text.analytics.process.channel" queue-names="${sda.text.analytics.process.queue}"
connection-factory="sda.text.analytics.connectionFactory" prefetch-count="${sda.mule.prefetchCount}"
concurrent-consumers="${uima.process.threads}" task-executor="analyticsExecutor" receive-timeout="5000"/>
<int:json-to-object-transformer input-channel="sda.text.analytics.process.channel" type="com.issinc.sda.ingest.impl.IngestBean"/>
<bean id="analyticsExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="${uima.process.threads}" />
<property name="maxPoolSize" value="${uima.process.threads}" />
<property name="queueCapacity" value="${sda.mule.prefetchCount}" />
</bean>
<!-- Service that listens for an inbound messages, processes the text and sends the processed text back -->
<int:service-activator input-channel="sda.text.analytics.process.channel" output-channel="sda.text.analytics.response.channel"
ref="asyncExtractionService" method="processMessage" >
</int:service-activator>
<!--<rabbit:listener-container connection-factory="sda.connectionFactory" message-converter="jsonMessageConverter">
<rabbit:listener ref="asyncExtractionService" method="processMessage" queue-names="${sda.process.queue}" />
</rabbit:listener-container>-->

You're not really "using" the service activator at all; you are invoking the same bean/method as the service activator.
Consider using an AMQP inbound channel adapter to send messages to the service activator via the sda.process.channel.

Related

Spring Integration TCP - request/response switch request to the channels

I am doing Spring Integration with Server and Client request/response demo. The request comes with a Byte array which is to be converted to Object. Then the request comes to the input channel, I need to check which class is to be send to the service activator. Then the service activator will send it to the reply channel.
<bean id="javaSerializer"
class="org.springframework.core.serializer.DefaultSerializer"/>
<bean id="javaDeserializer"
class="org.springframework.core.serializer.DefaultDeserializer"/>
<!-- single-use="true" : A new message has to wait until the reply to the previous message has been received -->
<int-ip:tcp-connection-factory id="server"
type="server"
host="localhost"
port="10101"
single-use="true"
so-timeout="10000"
serializer="javaSerializer"
deserializer="javaDeserializer"
task-executor="severTaskExecutor"/>
<int-ip:tcp-inbound-gateway id="inGateway"
request-channel="inputChannel"
reply-channel="replyChannel"
connection-factory="server"
reply-timeout="10000"/>
<int:channel id="inputChannel"/>
<!-- How to switch the request to the different channel??? -->
<int:channel id="myChannelOne"/>
<int:channel id="myChannelTwo"/>
<int:service-activator
input-channel="myChannelOne"
output-channel="replyChannel"
ref="myServiceOne"
method="get" />
<int:service-activator
input-channel="myChannelTwo"
output-channel="replyChannel"
ref="myServiceTwo"
method="get" />
<int:channel id="replyChannel"/>
<bean id="myServiceOne" class="com.my.demo.MyServiceOne"/>
<bean id="myServiceTwo" class="com.my.demo.MyServiceTwo"/>
Use a payload type router https://docs.spring.io/spring-integration/docs/current/reference/html/message-routing.html#router-implementations-payloadtyperouter
<int:payload-type-router input-channel="routingChannel">
<int:mapping type="java.lang.String" channel="stringChannel" />
<int:mapping type="java.lang.Integer" channel="integerChannel" />
</int:payload-type-router>

Migration Of Spring Batch from 2.2 to 4.x (XML Configuration Of Partition Jobs

I am migrating Spring Batch Partition Jobs with XML configuration to Spring batch 4.x. I am trying to take advantage to an improvement in the MessageChannelPartitionHandler where it looks for completion of remote steps with both a reply channel and a datasource polling.
When I use this configuration:
<int:channel id="partitioned.jms.requests">
<int:dispatcher task-executor="springbatch.partitioned.jms.taskExecutor"/>
</int:channel>
<int:channel id="partitioned.jms.reply" />
<bean id="partitioned.jms.handler" class="org.springframework.batch.integration.partition.MessageChannelPartitionHandler">
<property name="messagingOperations">
<bean class="org.springframework.integration.core.MessagingTemplate">
<property name="defaultChannel" ref="partitioned.jms.requests"/>
</bean>
</property>
<property name="stepName" value="process.partitioned.step"/>
<property name="gridSize" value="${process.step.partitioned.gridSize}"/>
<property name="dataSource" ref="springbatch.repositoryDataSource" />
<property name="pollInterval" value="${springbatch.partition.verification.interval}"/>
</bean>
The step completes but I see an error in the logs.
no output-channel or replyChannel header available
I looked at the class and see I can add a replyChannel property to the MessageChannelPartitionHandler class. If I add the following:
<property name="replyChannel" ref="claim.acp.process.partitioned.jms.reply"/>
I get error back that a pollable channel is needed.
How do I create a pollable channel (assuming from the same JMS queue)?
You need to show the rest of your configuration.
If you are using DB polling for the results, set the output-channel on the jms outbound gateway to "nullChannel" and the replies received over JMS will be discarded.
Or, use an outbound channel adapter (instead of a gateway) (and an inbound-channel-adapter on the slaves). That avoids the replies being returned altogether.
You have to set pollRepositoryForResults to true.
To answer your specific question
<int:channel id="replies>
<int:queue />
<int:channel>

Inconsistency Dequeue issues with Spring Integration with Oracle AQ

I am using Spring integration with Oracle AQ,configuration code is as below.
Currently with the below configuration,the service activator is not getting invoked consistently with even the dequeue was successful at oracle end, unable to trace the message after successful Dequeue with the application logs, not even single error message shown on the log. Tried Debug,Trace and info options in the jms adaptor, but no clue from the log details. I have verified with Oracle team on enque and deque messages, but the health check reports are clearing mentioning the messages are dequeued successfully.
Badly required your help to get rid of this inconsitency behaviour while invoking the service activator using spring
<int:logging-channel-adapter id="jmslogger" log-full-message="true" level="TRACE"/>
<!-- Oracle Advanced Queue Integration -->
<bean id="jdbc4NativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.Jdbc4NativeJdbcExtractor"
p:connectionType="oracle.jdbc.driver.OracleConnection" />
<orcl:aq-jms-connection-factory
id="oracleAqConnectionFactory"
use-local-data-source-transaction="true"
native-jdbc-extractor="jdbc4NativeJdbcExtractor"
data-source="dataSource"/>
<!-- Siebel Atlas Service Request - Oracle Advanced Queue Integration -->
<bean id="jmsJsonMessageConverter" class="org.springframework.jms.support.converter.MappingJackson2MessageConverter"
p:typeIdPropertyName="javaDtoClass"
/>
<int:channel id="submitSiebelAtlasCreateServiceRequestOutboundRequestChannel" ></int:channel>
<int:channel id="submitSiebelAtlasCreateServiceRequestOutboundRequestEnrichedChannel" >
<int:interceptors>
<int:wire-tap channel="jmslogger"/>
</int:interceptors>
</int:channel>
<int:channel id="createSiebelAtlasCreateServiceRequestOutboundReplyChannel" />
<int:logging-channel-adapter id="createSiebelAtlasCreateServiceRequestOutboundReplyChannelLogger"
channel="createSiebelAtlasCreateServiceRequestOutboundReplyChannel" />
<int:gateway
id="submitSiebelAtlasCreateServiceRequestMessagingService"
service-interface="ServiceRequestOutboundGatewayMessagingService"
default-request-channel="submitSiebelAtlasCreateServiceRequestOutboundRequestChannel"
default-reply-channel="submitSiebelAtlasCreateServiceRequestOutboundReplyChannel" />
<int:header-enricher input-channel="submitSiebelAtlasCreateServiceRequestOutboundRequestChannel" output-channel="submitSiebelAtlasCreateServiceRequestOutboundRequestEnrichedChannel">
<int:correlation-id expression="payload.getRequestId()"/>
</int:header-enricher>
<!-- Outbound driven channel adapter, meaning messagings are being sent to / queued in AQ -->
<int-jms:outbound-channel-adapter
id="siebelAtlasCreateServiceRequestJmsOutboundChannelAdapter"
destination-name="Q_NAME"
channel="submitSiebelAtlasCreateServiceRequestOutboundRequestEnrichedChannel"
connection-factory="oracleAqConnectionFactory"
message-converter="jmsJsonMessageConverter"
auto-startup="true">
</int-jms:outbound-channel-adapter>
<int:service-activator
output-channel="createSiebelAtlasCreateServiceRequestOutboundReplyChannel"
input-channel="createSiebelAtlasCreateServiceRequestInboundRequestChannel"
ref="createCustomerRelationshipsSiebelAtlasServiceRequestService"
method="create">
</int:service-activator>
<int:channel id="createSiebelAtlasCreateServiceRequestInboundRequestChannel">
<int:interceptors>
<int:wire-tap channel="jmslogger"/>
</int:interceptors>
</int:channel>
<!-- Inbound message driven channel adapter, meaning messagings are being consumed / dequeued from AQ -->
<int-jms:message-driven-channel-adapter connection-factory="oracleAqConnectionFactory"
message-converter="jmsJsonMessageConverter"
destination-name="Q_NAME"
channel="createSiebelAtlasCreateServiceRequestInboundRequestChannel"
acknowledge="transacted"
max-concurrent-consumers="5"
transaction-manager="transactionManager"
auto-startup="true"
concurrent-consumers="2" />

Receive the acknowledgement from TCP server to our application using spring Integration

Currently we are using Spring Integration 2.1.0 Release in our application.
Application flow is as below:
Some operation is performed in application and we got the output string in String via Active MQ.
I have used message-driven-channel-adapter and service-activator to read the data from queue.
That data is displayed successfully on Server(application is working as client) using tcp-outbound-gateway.
Problem is while getting the acknowledgement from server.
Created a new channel and entered in reply-channel in tcp-outbound-gateway
Passing the same channel in service-activator as input channel.
It is showing below error:
[task-scheduler-5] 2017-10-05 18:32:20,732 ERROR org.springframework.integration.handler.LoggingHandler - org.springframework.integration.MessageDeliveryException: Dispatcher has no subscribers.
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:108)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:101)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:61)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:149)
Code is as below
<context:property-placeholder />
<!-- Gateway and connection factory setting -->
<int:channel id="telnetLandingChannel" />
<int:channel id="telnetReplyChannel" />
<beans:bean id="clientCustomSerializer"
class="com.telnet.core.serializer.CustomSerializer">
<beans:property name="terminatingChar" value="10" />
<beans:property name="maxLength" value="65535" />
</beans:bean>
<int:gateway id="gw" default-reply-channel="telnetReplyChannel" default-reply-timeout="100000"
service-interface="com.telnet.core.integration.connection.ParseTcpConfiguration$SimpleGateway"
default-request-channel="telnetLandingChannel"/>
<ip:tcp-connection-factory id="clientFactory"
type="client" host="localhost" port="7777" single-use="false" using-nio="false"
serializer="${client.serializer}" deserializer="${client.serializer}" />
<ip:tcp-outbound-gateway id="clientInGw"
request-channel="telnetLandingChannel"
connection-factory="clientFactory"
reply-channel="telnetReplyChannel"
reply-timeout="100000"/>
<!-- To send the messege over server via JMS and serviceActivator -->
<int:channel id="incidentDispatchMessageChannel" />
<int:channel id="jmsChannel" />
<beans:bean id="customClientServiceActivator"
class= "com.telnet.core.integration.CustomClientServiceActivator">
</beans:bean>
<int-jms:message-driven-channel-adapter id="incidentDispatchMessageChannelAdapter" error-channel="errorChannel"
connection-factory="mqConnectionFactory"
destination-name="${incident.processing.messaging.dispatch.queues}"
channel="incidentDispatchMessageChannel"/>
<int:service-activator id="incidentMessageActivator"
input-channel="incidentDispatchMessageChannel"
output-channel="jmsChannel"
ref="customClientServiceActivator" method="getOutboundMessage">
</int:service-activator>
<int:object-to-string-transformer id="clientBytes2String"
input-channel="jmsChannel"
output-channel="telnetLandingChannel"/>
<!-- To receive the acknowledgement message on server via serviceActivator -->
<int:service-activator id="incidentAck"
input-channel="telnetReplyChannel"
ref="customClientServiceActivator" method="getAck">
</int:service-activator>
I have studied various article on stackverFlow but not able to get any solution
Yeah... That isn't clear by the error what channel is guilty.
On the other hand you really use very old Spring Integration version.
Would be great to consider to upgrade to the latest: http://projects.spring.io/spring-integration/.
However I think that issue is somehow around exactly that reply-channel, which you use not only for the <service-activator> but for the <int:gateway> as well.
I suggest you to remove default-reply-channel="telnetReplyChannel" from the gateway definition, remove reply-channel="telnetReplyChannel" from the <ip:tcp-outbound-gateway> definition. And let them communicate via replyChannel header populated by the gateway during request.
Regarding your <int-jms:message-driven-channel-adapter> flow which leads to the same <ip:tcp-outbound-gateway>, I would suggest to still stay with the replyChannel header but here populate it via <header-enricher> before sending message to the telnetLandingChannel. That replyChannel via <header-enricher> would be exactly an input-channel for the subsequent <int:service-activator> to handle ack from the <ip:tcp-outbound-gateway>.
I got the solution of this issue, there are multiple xmls in our code but i have added the code in one to show flow in stackOverflow.
Issue was i had defined in a xml which has only configuration part like Outbound adapter connection factory where as it should be defined in another xml where I am using service activator. Changed the place of channel definition and it worked.
I want to disconnect the TCP (as server) the moment i got the response message. As of now I am using so-timeout, so my TCP server will gets timedout after the time given in so-timeout, but requirement is to disconnect the connection the moment TCP print/display the acknowledgement. Please suggest how can I implement this.

Spring Integration Kafka threading config

I'm using spring-integration-kafka 1.1.0 with the following config. I don't quite understand about the streams config. When I increase this, does Spring automatically spawn more threads to handle the messages? e.g. when I have streams=2, does the correlated transformer and service-activator all run in 2 threads? I feel like missing some thread-executor configurations, but not sure how. Any hint is appreciated. Thanks.
<int:poller default="true" fixed-delay="10"/>
<int:channel id="tag.track">
</int:channel>
<int-kafka:inbound-channel-adapter id="kafkaInboundChannelAdapterForTagTrack" kafka-consumer-context-ref="consumerContextForTagTrack" auto-startup="true" channel="tag.track">
</int-kafka:inbound-channel-adapter>
<int-kafka:consumer-context id="consumerContextForTagTrack"
consumer-timeout="${kafka.consumer.timeout}" zookeeper-connect="zookeeperConnect">
<int-kafka:consumer-configurations>
<int-kafka:consumer-configuration group-id="${kafka.consumer.group.track}" max-messages="200">
<int-kafka:topic id="tag.track" streams="2" />
</int-kafka:consumer-configuration>
</int-kafka:consumer-configurations>
</int-kafka:consumer-context>
<int:channel id="tag.track.transformed">
<int:interceptors>
<int:wire-tap channel="event.logging" />
</int:interceptors>
</int:channel>
<int:transformer id="kafkaMessageTransformerForTagTrack"
ref="kafkaMessageTransformer" input-channel="tag.track" method="transform"
output-channel="tag.track.transformed" />
<int:service-activator input-channel="tag.track.transformed" ref="tagTrackMessageHandler" method="handleTagMessage">
<int:request-handler-advice-chain>
<ref bean="userTagRetryAdvice" />
</int:request-handler-advice-chain>
</int:service-activator>
Tried message-driven-channel-adapter, but can't get it work, the following config doesn't pick up any message. Also tried the org.springframework.integration.kafka.listener.KafkaTopicOffsetManager , it complains Offset management topic cannot have more than one partition. Also, in this adapter, how to configure the consumer group?
Is there any detailed example on how to use the message-driven-channel-adapter? The instruction on the project page is pretty high level.
<int:channel id="tag.track">
<int:queue capacity="100"/>
</int:channel>
<bean id="kafkaConfiguration" class="org.springframework.integration.kafka.core.ZookeeperConfiguration">
<constructor-arg ref="zookeeperConnect"/>
</bean>
<bean id="connectionFactory" class="org.springframework.integration.kafka.core.DefaultConnectionFactory">
<constructor-arg ref="kafkaConfiguration"/>
</bean>
<bean id="decoder" class="org.springframework.integration.kafka.serializer.common.StringDecoder"/>
<int-kafka:message-driven-channel-adapter
id="adapter"
channel="tag.track"
connection-factory="connectionFactory"
key-decoder="decoder"
payload-decoder="decoder"
max-fetch="100"
topics="tag.track"
auto-startup="true"
/>
The streams property has nothing to do with Spring itself; it's simply passed to Kafka when invoking ConsumerConnector.createMessageStreams() (each topic/streams entry is passed in the map argument).
Refer to the kafka documentation.
EDIT:
When using the high-level consumer, the kafka inbound channel adapter is polled, so the threads on which the downstream integration flow runs are not related to the kafka client threads; they are managed in the poller configuration.
You could consider using the message-driven channel adapter instead.

Resources