在 Spring 集成中,消息并行传递到数据库以及生产者端 (jms)



我正在做一个关于 Spring 与 (jms(activemq 集成的示例项目。要求是将数据存储到数据库并将该数据传递到 activemq 中的队列,两者都应该并行工作。在向生产者端发送消息时收到错误,例如"嵌套异常是java.lang.IllegalStateException:类型为[class userDetails.web.QkaapzzMessageProducer]的目标对象没有处理消息的合格方法。

<int:publish-subscribe-channel id="postChannel" />      
<jms:inbound-channel-adapter id="jmsIn"
destination="helloWorldJMSQueue"
channel="postChannel"
extract-payload="false" 
auto-startup="true">
<int:poller fixed-delay="3000" />
</jms:inbound-channel-adapter>                                     
<jms:message-driven-channel-adapter id="helloWorldJMSAdapater" destination="helloWorldJMSQueue" connection-factory="jmsConnectionFactory"
channel="postChannel" />

<integration:service-activator id="helloWorldServiceActivator" input-channel="postChannel" 
ref="qkaapzzMessageProducer" method="sendMessage" output-channel="nullChannel" />                                                                                                       

<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>

我的生产者类

public class QkaapzzMessageProducer {
private Connection connection;
private Session session;
private javax.jms.MessageProducer messageProducer;
public static final String HELLO_WORLD_QUEUE = "testQueue";
public Message<?> sendMessage(Message<?> msg,String queue2) throws 
JMSException {
if((queue2.equals("")) ||(queue2.equals(null)) )
{   
queue2=HELLO_WORLD_QUEUE;
session =
connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(queue2);
messageProducer = session.createProducer(queue);
// TextMessage txt = session.createTextMessage(text);
messageProducer.send((javax.jms.Message) msg);
// TODO Auto-generated method stub
}
else      
{
session =connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(queue2);
messageProducer = session.createProducer(queue);
messageProducer.send((javax.jms.Message) msg);
}
return msg;
}
}

此外,我需要将该消息从队列传递给消费者。我是这一切的新手,并帮助我找到解决方案

您的问题不清楚,因为您显示的问题与问题的主题无关。

您的异常表明sendMessage()方法签名不适合消息传递模型。

它在那里像:

public Message<?> sendMessage(Message<?> msg, String queue2) throws 

Spring 集成基于Message<?>对象交换。因此,当服务激活器尝试调用该方法时,它手中只有一个请求Message<?>,并且完全不知道该queue2参数是什么以及如何处理它。

您可以在该queue2参数上放置一个@Header注释。当然,如果您确实在消息标头中有该信息,它将起作用。

有关详细信息,请参阅参考手册。

最新更新