简体   繁体   English

Spring集成-入站通道适配器是多线程的吗?

[英]Is Spring integration - inbound channel adapter multithreaded?

I have the following spring-integration configuration v1.0.4. 我具有以下spring-integration配置v1.0.4。

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mail="http://www.springframework.org/schema/integration/mail"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
    http://www.springframework.org/schema/integration/mail
    http://www.springframework.org/schema/integration/mail/spring-integration-mail-2.1.xsd 
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-2.0.xsd">


    <util:properties id="javaMailProperties">
    <prop key="mail.imap.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
    <prop key="mail.imap.socketFactory.fallback">false</prop>
    <prop key="mail.store.protocol">imaps</prop>
    <prop key="mail.debug">false</prop>
</util:properties>

 <mail:inbound-channel-adapter id="imapAdapter"
                                  store-uri="imaps://user:pass@domain:993/inbox"                                    
                                  channel="recieveEmailChannel"
                                  auto-startup="true"                                      
                                  java-mail-properties="javaMailProperties">
    <int:poller> 
    <int:interval-trigger initial-delay="1000" interval="2000"
    fixed-rate="true"/>
    </int:poller>
</mail:inbound-channel-adapter>

<int:channel id="recieveEmailChannel">        
    <int:interceptors>
        <int:wire-tap channel="logger"/>
    </int:interceptors>
</int:channel>

<int:logging-channel-adapter id="logger" level="DEBUG"/>

<int:service-activator input-channel="recieveEmailChannel" ref="emailReceiverService" method="receive"/>

<bean id="emailReceiverService" class="com.mycompany.DefaultEmailReceiverUtilService">
</bean>

DefaultEmailReceiverUtilService DefaultEmailReceiverUtilService

public class DefaultEmailReceiverUtilService implements
        EmailReceiverUtilService
{

    public void receive(Message<?> message)
    {
        //Processing the emails
    }
}

Question: 题:

  1. Is it multithreaded? 是多线程的吗? or the Emails will be processed in a serial fashion?. 还是将以串行方式处理电子邮件? If yes then how to make it multithreaded? 如果是,那么如何使其成为多线程?
  2. When my application is running in eclipse debug mode, I can see some Timer task threads, but each request is going to same timer task in a sequential fashion, also my number of threads (Timer task) are steadily growing. 当我的应用程序以eclipse调试模式运行时,我可以看到一些Timer任务线程,但是每个请求都以顺序的方式进入同一计时器任务,而且我的线程数(Timer任务)也在稳步增长。 I may be misinterpret it. 我可能会误解它。

Please correct me if I am wrong. 如果我错了,请纠正我。

What I think you need is a queue channel. 我认为您需要的是队列通道。 Your receiveEmailChannel should be something like: 您的receiveEmailChannel应该类似于:

<int:channel id="recieveEmailChannel">  
<int:queue/>
<int:interceptors>
    <int:wire-tap channel="logger"/>
</int:interceptors>
</int:channel>

Which I'm sure you'll know is how you define a queue channel. 我确定您将知道如何定义队列通道。 The point to point channel which is what you have currently is synchronous it can only have 1 message passed at a time. 当前正在同步的点对点通道,一次只能传递1条消息。

Currently if you'd add something to that channel it would wait until the service activator has finished whilst with a queue channel the service activator should fire off a new thread as soon as it detects something in the queue. 当前,如果您要向该通道添加某些内容,它将等待服务激活器完成,而使用队列通道时,服务激活器应在检测到队列中的某些内容时立即触发新线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM