ImapIdleChannelAdapter task-scheduler threads configuration - java

I've been playing with the ImapIdleChannelAdapter integrated with Spring for a few.. and noticed that it starts 10 task-scheduler threads.
Mostly I have been checking the documentation for the ImapIdleChannelAdapter, but was not able to find a way to config how many threads it will start when listening to a email inbox.
Here is my Spring config:
<int:channel id="receiveChannel" >
<int:dispatcher task-executor="threadPool" />
</int:channel>
<int-mail:imap-idle-channel-adapter id="imapAdapter"
store-uri="imaps://#{systemProperties['imaps.encoded.username']}:#{systemProperties['imaps.encoded.password']}##{systemProperties['imaps.host']}:#{systemProperties['imaps.port']}/INBOX"
channel="receiveChannel" auto-startup="true" should-delete-messages="false" should-mark-messages-as-read="false"
java-mail-properties="javaMailProperties">
</int-mail:imap-idle-channel-adapter>
Thanks for the help.

by setting the number of threads in your executor -- it's the configuration of your "threadPool" bean not, of the imapAdapter itself -- though you can further configure the threading of the imapAdapter with setSendingTaskExecutor() and setTaskScheduler().

Related

How to solve exception with inbound-channel-adapter poller?

Сould not find an answer.
Spring version 5.0.6.
My config:
<int:channel id="data"/>
<int:inbound-channel-adapter
id="dataAdapter"
channel="data"
auto-startup="false"
ref="dataGetter"
method="myMessageSource">
<int:poller max-messages-per-poll="10"/>
</int:inbound-channel-adapter>
<beans:bean
class="org.endpoints.DataGetter"
id="dataGetter"/>
Throw exception:
Configuration problem: A <poller> must have one and only one trigger configuration.
If no poller:
No poller has been defined for channel-adapter 'dataAdapter', and no default poller is available within the context.
How to properly setup the poller?
Look at your config:
<int:poller max-messages-per-poll="10"/>
You don't meet the condition to have or fixed-delay, or fixed-rate, or cron, or just trigger reference: https://docs.spring.io/spring-integration/docs/5.0.6.RELEASE/reference/html/messaging-endpoints-chapter.html#endpoint-namespace

SPRING BATCH : How to configure remote chunking for multiple jobs running in a task executor

I am new to spring batch processing. I am using remote chunking where there is a master , multiple slaves and ActiveMQ for messaging.
Master has a job and a job launcher and the job launcher has a task-executor which is having following configuration
<task:executor id="batchJobExecutor" pool-size="2"queue-capacity="100" />.
Chunk configuration is
<bean id="chunkWriter"
class="org.springframework.batch.integration.chunk.ChunkMessageChannelItemWriter" scope="step">
<property name="messagingOperations" ref="messagingGateway" />
<property name="replyChannel" ref="replies" />
<property name="throttleLimit" value="50" />
<property name="maxWaitTimeouts" value="60000" />
</bean>
<bean id="chunkHandler"
class="org.springframework.batch.integration.chunk.RemoteChunkHandlerFactoryBean">
<property name="chunkWriter" ref="chunkWriter" />
<property name="step" ref="someJobId" />
</bean>
<integration:service-activator
input-channel="requests" output-channel="replies" ref="chunkHandler" />
So we are allowed to run two jobs at a time and the remaining jobs will be in the queue.
When two jobs are submitted Master is creating the chunk and submitting to the queue and slave is processing.
But the acknowledgment from the slave to master is giving error
java.lang.IllegalStateException: Message contained wrong job instance id [9331] should have been [9332].
at org.springframework.util.Assert.state(Assert.java:385) ~[Assert.class:4.1.6.RELEASE]
at org.springframework.batch.integration.chunk.ChunkMessageChannelItemWriter.getNextResult
Please help me with this.
The ChunkMessageChannelItemWriter is only designed for one concurrent step - you need to put it in step scope so each job gets its own instance - see this test case
EDIT
Actually, no; that won't work - since the bean instances are using the same reply channel, they could get each other's replies. I opened a JIRA Issue.
This is a very old post, but I think the issue you see here might be related to the throttle limit being larger than the maxWaitTimouts value 4.
What we have seen is that the implementation will not read more than maxWaitTimeouts entries from the reply queue after the job finished. I think this is a bug.
See also the question I asked on stackoverflow here : Remote batch job does not read all responses in afterStep method
I made a bug report for this as well: https://jira.spring.io/browse/BATCH-2651 and am creating a PR to fix the issue.

Multiple service activators of same input channel in spring integration

I have a requirement of processing the same information of a request in two different ways asynchronously. I am using spring integration in my project.
Can I have two service activators reading from the same input channel as below? I will get my data from a queue through an adapter and forwarded to the channel.
<int:channel id="dataChannel" />
<service-activator input-channel="dataChannel" ref="serviceA" method="method1">
<service-activator input-channel="dataChannel" ref="serviceB" method="method2">
<bean id="serviceA" class="a.b.test.ServiceA">
<bean id="serviceB" class="a.b.test.ServiceB">
Change dataChannel to
<int:publish-subscribe-channel id=`dataChannel` task-executor="exec" />
(declare a <task:executor ... />).

Adding multiple listener-container, with ids, does not seem to work

I have a rabbitMQ configuration where in I need to have two separate listener-containers, each having a set of listeners. Here is a snippet from rabbitmq-context.xml:
<rabbit:listener-container
connection-factory="connectionFactory" message-converter="jsonMessageConverter"
auto-startup="true"
acknowledge="manual"
requeue-rejected="true"
concurrency="5"
task-executor="myTaskExecutor" >
<rabbit:listener queues="Queue1" ref="myQ1Listener" method="onMessage"/>
</rabbit:listener-container>
<rabbit:listener-container
connection-factory="connectionFactory" message-converter="jsonMessageConverter"
auto-startup="true"
acknowledge="manual"
requeue-rejected="false"
concurrency="5"
task-executor="myTaskExecutor" >
<rabbit:listener queues="Queu2" ref="myQ2Listener" method="onMessage"/>
</rabbit:listener-container>
If these are specified without an id all the listeners are started on initialization.
If I go ahead and specify an id to one of them (which I want to reference in another bean), the other listener-container (without the id) does not get initialized.
If I specify ids with both these listener-containers (and do not reference those ids anywhere), still listeners from only one of the listener-containers are initialized.
Can anybody help me understand if there its a configuration issue or is this a bug in RabbitMQ?
This issue has been fixed (https://jira.spring.io/browse/AMQP-332) according to SO question Adding multiple listeners which will listen to different RabbitMQ queue not working.
So, show, please, the wrong config and try to upgrade to te latest Spring AMQP version.
Acutally we have similar test-case. I've just removed the id from nexted <rabbit:listener> elements and the ListenFromAutoDeleteQueueTests passed.
Please, check versions of Spring jars and try to use the latests.

Combine few channels in Spring Integration

I have a heavy loaded (allot of external network calls) integration flow, which uses PriorityQueue before entering main Service Activator. I want to add executor channel to improve the system load, but I see no straight forward ways to combine those channels.
<int:channel id="monitorInPriorityUpdate">
<int:priority-queue/>
</int:channel>
<int:transformer id="monitorLogTransformerStub"
input-channel="monitorInPriorityUpdate" output-channel="monitorInUpdate"
expression="payload" />
<int:channel id="monitorInUpdate">
<int:dispatcher task-executor="monitorExecutor"/>
</int:channel>
I needed to create 2 additional components, to make this work, but is there a way to combine few Spring Integration Channels in one, without adding new components?
Actually, looks like not ebough info. But I try to guess. You need this:
<int:channel id="priorityChannel">
<int:priority-queue/>
</int:channel>
<int:bridge input-channel="priorityChannel" output-channel="executorChannel">
<int:poller fixed-rate="100"/>
</int:bridge>
<int:channel id="executorChannel">
<int:dispatcher task-executor="threadPoolExecutor"/>
</int:channel>
Here you use a Bridge to shift messages from one channel to another one.
OR this:
<int:channel id="priorityChannel">
<int:priority-queue/>
</int:channel>
<int:service-activator input-channel="priorityChannel" ref="service">
<int:poller fixed-rate="100" task-executor="threadPoolExecutor"/>
</int:service-activator>
Here you just place your messages from priorityChannel to taskExecutor using Poller.
It is abnormal to mix concerns in one channel. Each channel type plays his own concreate role.
What you want to achieve is not just minimize typing, but even if that happen to be a solution for you, it would be very complex and not robust.

Categories