Activemq设置 - 无法将消息发送到队列(错误 - java.io.IOException:未知数据类型:47)

时间:2014-11-15 16:42:23

标签: java spring jms activemq

我已安装ActiveMQ并可以访问 - http:/ ** / admin / queues.jsp的网址。 当我尝试将消息发送到队列时,我得到了下面的错误。 示例代码如下所示

public class MessageReceiver {
    public static void main(String[] args) throws JMSException {
          ApplicationContext context = new ClassPathXmlApplicationContext("spring-beans.xml");
          JmsTemplate jmsTemplate=(JmsTemplate) context.getBean("jmsTemplate");
          jmsTemplate.send(
                new MessageCreator() {
                      public ObjectMessage  createMessage(Session session) throws JMSException {
                          ObjectMessage message = session.createObjectMessage();
                          message.setObject("My first Message");                      
                           return message;

                  }
    }  );

      System.out.println("MESSAGE SENT TO myMessageQueue");
      Message receivedMessage=jmsTemplate.receive("queue");
      ObjectMessage msg = (ObjectMessage)receivedMessage;
      System.out.println("Message Received :"+msg.getObject().toString());

}

Spring xml是

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL">
        <value>tcp://**:8161</value>
    </property>
    <property name="userName">
        <value>admin</value>
    </property>
    <property name="password">
        <value>admin</value>
    </property>
</bean>
<bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg value="queue" />
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="connectionFactory" />
    <property name="defaultDestination" ref="destination" />
</bean>

错误是

log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.springframework.jms.UncategorizedJmsException: Uncategorized exception occured during JMS processing; nested exception is javax.jms.JMSException: Unknown data type: 47
    at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:316)
    at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:469)
    at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:534)
    at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:526)
    at com.example.example.MessageReceiver.main(MessageReceiver.java:15)
Caused by: javax.jms.JMSException: Unknown data type: 47
    at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:72)
    at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1435)
    at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1522)
    at org.apache.activemq.ActiveMQConnection.createSession(ActiveMQConnection.java:328)
    at org.springframework.jms.support.JmsAccessor.createSession(JmsAccessor.java:196)
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:457)
    ... 3 more
Caused by: java.io.IOException: Unknown data type: 47
    at org.apache.activemq.openwire.OpenWireFormat.doUnmarshal(OpenWireFormat.java:348)
    at org.apache.activemq.openwire.OpenWireFormat.unmarshal(OpenWireFormat.java:268)
    at org.apache.activemq.transport.tcp.TcpTransport.readCommand(TcpTransport.java:221)
    at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:213)
    at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:196)
    at java.lang.Thread.run(Thread.java:662)

有人可以帮我解决这个问题吗?感谢..

4 个答案:

答案 0 :(得分:18)

&#39;未知数据类型:47&#39;错误是由于您用于以下代理URL的配置:

<value>tcp://**:8161</value>

问题是端口号不正确。端口8161是ActiveMQ Web控制台运行的位置。这解释了您正在查看的错误消息和堆栈跟踪。每当您在此地址(*:8161)访问代理的Web控制台时,都会抛出异常。

要解决此问题,请将端口号更改为ActiveMQ TCP传输正在侦听的端口。我猜测它可能是默认端口号61616

答案 1 :(得分:0)

我认为以下是错误:

<value>tcp://**:8161</value>
你的xml中的

确保将实际地址放在那里。

答案 2 :(得分:0)

即使 brokerURL 设置正确,只有像我这样的人也有同样的错误。 检查 ProducerTemplate 类的用法:例如,在我的代码中,我错过了生产者的 sendBody 方法中的 ExchangePattern 参数。 / p>

希望这个帮助

答案 3 :(得分:0)

默认情况下,8161 是 http 端口,而 tcp 端口是 61616。请检查 active mq 的日志以获取正确的端口。

 INFO | Listening for connections at: tcp://localhost:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600
 INFO | ActiveMQ WebConsole available at http://0.0.0.0:8161/
 INFO | ActiveMQ Jolokia REST API available at http://0.0.0.0:8161/api/jolokia/