我正在与(jms)activemq进行spring集成的示例项目。要求是将数据存储到数据库并将该数据传递到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;
}
}
此外,我需要将该消息从队列传递给消费者。我是新手,帮助我找到解决方案
答案 0 :(得分:0)
您的问题并不清楚,因为您显示的问题与问题的主题无关。
您的例外情况表明sendMessage()
方法签名不适合Messaging模型。
就像那样:
public Message<?> sendMessage(Message<?> msg, String queue2) throws
Spring Integration基于Message<?>
对象交换。因此,当Service Activator尝试调用该方法时,它只有一个请求Message<?>
,并且完全不知道该queue2
参数是什么以及如何处理它。
您可以帮助它在@Header
参数上添加queue2
注释。当然,如果您真的在邮件标题中包含该信息,它将会起作用。
查看Reference Manual中的更多信息。