我只是想使用spring从队列中读取消息,所以得到了很多
no dispatcher for MessageDispatch
调试日志。我想使用方法JmsMessagingTemplate.receiveAndConvert()
自动将收到的消息转换为目标类。在示例中,我通过JmsMessagingTemplate.receive()
将其删除。
现在我为这个问题精简了代码。 代码是:
public class JmsReceiver {
@Autowired
private JmsMessagingTemplate jmsMsgTemplate;
private Queue queue;
public JmsReceiver() {
}
public JmsReceiver(Queue queue) {
this.queue = queue;
}
public void nowReceive() {
while (true) {
try {
Object o = jmsMsgTemplate.receive(this.queue);
System.out.println(o);
} catch (Exception exc) {
exc.printStackTrace();
}
}
}
}
Spring配置为:
<bean id="targetConnectionFactory"
class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="connectionFactory"
ref="activeMqConnectionFactory" />
<property name="idleTimeout" value="0" />
</bean>
<bean id="activeMqConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
</bean>
<bean id="connectionFactory"
class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="reconnectOnException" value="true" />
<property name="targetConnectionFactory">
<ref bean="targetConnectionFactory" />
</property>
</bean>
<jee:jndi-lookup id="messagesQueueJndi"
jndi-name="jms/queue/LogMessagesT" />
<bean id="messageReceiver "
class="com.objectbyte.measuretemp.server.main.JmsReceiver"
init-method="nowReceive">
<constructor-arg ref="messagesQueueJndi" />
</bean>
<bean id="jmsMsgTemplate"
class="org.springframework.jms.core.JmsMessagingTemplate">
<property name="connectionFactory" ref="connectionFactory" />
</bean>
日志为:
...
12:59:28.586 [main] DEBUG org.apache.activemq.ActiveMQMessageConsumer - on close, rollback duplicate: ID:Lando-37577-1545993352355-1:1:39:1:1
...
13:16:01.018 [ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@48688] DEBUG org.apache.activemq.ActiveMQConnection - org.apache.activemq.ActiveMQConnection$3@77d4a1c3 no dispatcher for MessageDispatch {commandId = 0, responseRequired = false, consumerId = ID:Lando-40433-1545999355422-1:1:1:1, destination = queue://LogMessages, message = ActiveMQBytesMessage {commandId = 460, responseRequired = false, messageId = ID:Lando-37577-1545993352355-1:1:92:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:Lando-37577-1545993352355-1:1:92:1, destination = queue://LogMessages, transactionId = null, expiration = 0, timestamp = 1545993359316, arrival = 0, brokerInTime = 1545993359316, brokerOutTime = 1545999359167, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@1760a940, marshalledProperties = org.apache.activemq.util.ByteSequence@4b531f68, dataStructure = null, redeliveryCounter = 0, size = 0, properties = {_type=[B, __AMQ_CID=ID:Lando-37577-1545993352355-0:1, timestamp=1545993359314}, readOnlyProperties = false, readOnlyBody = false, droppable = false, jmsXGroupFirstForConsumer = false} ActiveMQBytesMessage{ bytesOut = null, dataOut = null, dataIn = null }, redeliveryCounter = 0} in {ID:Lando-40433-1545999355422-1:1:-1:1=org.apache.activemq.AdvisoryConsumer@5201f451}
13:16:01.084 [ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@48688] DEBUG org.apache.activemq.ActiveMQConnection - org.apache.activemq.ActiveMQConnection$3@6800e43b no dispatcher for MessageDispatch {commandId = 0, responseRequired = false, consumerId = ID:Lando-40433-1545999355422-1:1:1:1, destination = queue://LogMessages, message = ActiveMQBytesMessage {commandId = 465, responseRequired = false, messageId = ID:Lando-37577-1545993352355-1:1:93:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:Lando-37577-1545993352355-1:1:93:1, destination = queue://LogMessages, transactionId = null, expiration = 0, timestamp = 1545993360818, arrival = 0, brokerInTime = 1545993360819, brokerOutTime = 1545999359167, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@3a089a41, marshalledProperties = org.apache.activemq.util.ByteSequence@28301ee9, dataStructure = null, redeliveryCounter = 0, size = 0, properties = {_type=[B, __AMQ_CID=ID:Lando-37577-1545993352355-0:1, timestamp=1545993360815}, readOnlyProperties = false, readOnlyBody = false, droppable = false, jmsXGroupFirstForConsumer = false} ActiveMQBytesMessage{ bytesOut = null, dataOut = null, dataIn = null }, redeliveryCounter = 0} in {ID:Lando-40433-1545999355422-1:1:-1:1=org.apache.activemq.AdvisoryConsumer@5201f451}
13:16:01.270 [ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@48688] DEBUG org.apache.activemq.ActiveMQConnection - org.apache.activemq.ActiveMQConnection$3@3a6d82db no dispatcher for MessageDispatch {commandId = 0, responseRequired = false, consumerId = ID:Lando-40433-1545999355422-1:1:1:1, destination = queue://LogMessages, message = ActiveMQBytesMessage {commandId = 480, responseRequired = false, messageId = ID:Lando-37577-1545993352355-1:1:96:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:Lando-37577-1545993352355-1:1:96:1, destination = queue://LogMessages, transactionId = null, expiration = 0, timestamp = 1545993362964, arrival = 0, brokerInTime = 1545993362965, brokerOutTime = 1545999359167, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@95043d0, marshalledProperties = org.apache.activemq.util.ByteSequence@56c521f0, dataStructure = null, redeliveryCounter = 0, size = 0, properties = {_type=[B, __AMQ_CID=ID:Lando-37577-1545993352355-0:1, timestamp=1545993362955}, readOnlyProperties = false, readOnlyBody = false, droppable = false, jmsXGroupFirstForConsumer = false} ActiveMQBytesMessage{ bytesOut = null, dataOut = null, dataIn = null }, redeliveryCounter = 0} in {ID:Lando-40433-1545999355422-1:1:-1:1=org.apache.activemq.AdvisoryConsumer@5201f451}
org.springframework.messaging.MessagingException: Connection closed; nested exception is javax.jms.IllegalStateException: Connection closed; nested exception is org.springframework.jms.IllegalStateException: Connection closed; nested exception is javax.jms.IllegalStateException: Connection closed
at org.springframework.jms.core.JmsMessagingTemplate.convertJmsException(JmsMessagingTemplate.java:454)
at org.springframework.jms.core.JmsMessagingTemplate.doReceive(JmsMessagingTemplate.java:379)
at org.springframework.jms.core.JmsMessagingTemplate.doReceive(JmsMessagingTemplate.java:47)
at org.springframework.messaging.core.AbstractMessageReceivingTemplate.receive(AbstractMessageReceivingTemplate.java:46)
所以我的问题是:为什么没有调度程序,为什么有例外?