繁体   English   中英

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

[英]ActiveMQ setup - Unable to send the message to Queue (error - java.io.IOException: Unknown data type: 47)

我已经安装了 ActiveMQ 并且可以访问 URL - http://localhost:8161/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());

}

弹簧 xml 是:

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL">
        <value>tcp://localhost: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)

“未知数据类型:47”错误是由于您对以下代理 URL 使用的配置造成的:

<value>tcp://localhost:8161</value>

问题是端口号不正确。 端口8161是嵌入式 ActiveMQ Web 服务器运行的地方,因此您可以访问 Web 控制台。 这解释了您看到的错误消息和堆栈跟踪。 每当您访问此地址 (*:8161) 处的代理的 Web 控制台时,都会引发异常。

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

我认为以下是错误:

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

在你的 xml 中。

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

对于像我这样的人来说,即使brokerURL设置正确,也会遇到同样的错误。 检查ProducerTemplate类的用法:例如在我的代码中,我错过了生产者的sendBody方法中的ExchangePattern参数。

希望这有帮助

默认情况下,8161 是 http 端口,而 tcp 端口是 61616。检查活动 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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM