通过jms将消息传递给生产者

时间:2018-05-28 10:59:53

标签: jms spring-integration activemq

如何通过spring集成将消息传递给producer(定义为将消息发送到activemq的方法)。 实际要求是,我需要将数据插入数据库并将数据移动到activemq中的队列,这两个操作都需要并行进行。我该怎么做。                 
   

 <jms:message-driven-channel-adapter id="helloWorldJMSAdapater" destination="helloWorldJMSQueue" connection-factory="jmsConnectionFactory"
    channel="postChannel"  />  


<int:channel id="requestChannel" />
<int:channel id="outputChannel" />

<int-http:inbound-gateway request-channel="requestChannel"
reply-channel="outputChannel" supported-methods="GET" path="/register"
view-name="register">
<int-http:request-mapping />
</int-http:inbound-gateway>
<int-http:inbound-gateway request-channel="postChannel"
reply-channel="outputChannel" supported-methods="POST" path="/registerNew"
error-channel="errorChannel" view-name="login">
</int-http:inbound-gateway>

<int-jdbc:outbound-channel-adapter 
    query="insert into user_registration (USER_FSTNAME,USER_ADDRESS,USER_STATE,USER_CITY,USER_OCCUPATION,USER_EMAIL,USER_CONTACT,USER_PASSWORD) 
values (:fstName,:addrss,:state,:city,:occupation,:email,:contact,:password)"
    channel="postChannel" data-source="dataSource" id="sample" sql-parameter-source-factory="spelSource"  />


<int:service-activator  ref="userService" input-channel="requestChannel"
                             output-channel="outputChannel"  method="message"/>

<bean id="spelSource"
    class="org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory">
    <property name="parameterExpressions">
        <map>                                                                                                                           
            <entry key="fstName" value="payload[firstName]" />
            <entry key="lstName" value="payload[lastName]" />
            <entry key="addrss" value="payload[address]" />
            <entry key="state" value="payload[state]" />                
            <entry key="city" value="payload[city]" />
            <entry key="occupation" value="payload[occupation]" />
            <entry key="email" value="payload[email]"/>
            <entry key="contact" value="payload[contact]"/>
            <entry key="password" value="payload[password]"/>
        </map>
    </property>
</bean>

1 个答案:

答案 0 :(得分:0)

使用<publish-subscribe-channel/>并为其订阅两个端点。它们将默认执行,或者如果您向通道添加task-executor,则会并行执行。