Activemq 设置 - 无法将消息发送到队列(错误 - java.io.IOException:未知数据类型:47)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26948124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Activemq setup - Unable to send the message to Queue (error - java.io.IOException: Unknown data type: 47)
提问by user1514499
I have installed ActiveMQ and could access the url at - http:/**/admin/queues.jsp. When I try to drop a message to a queue I am getting the below erro. The sample code is given below
我已经安装了 ActiveMQ 并且可以访问 URL - 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 is
弹簧 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>
Error is
错误是
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)
Can anyone please help me in fixing this? Thanks..
任何人都可以帮我解决这个问题吗?谢谢..
回答by SMA
The 'Unknown data type: 47' error is due to the configuration you are using for the following broker URL:
“未知数据类型:47”错误是由于您对以下代理 URL 使用的配置造成的:
<value>tcp://**:8161</value>
The problem is that the port number is incorrect. Port 8161 is where the ActiveMQ web console runs. This explains the error message and stack trace that you're seeing. Whenever you visit the web console for the broker at this address (*:8161) the exception is thrown.
问题是端口号不正确。端口 8161 是 ActiveMQ Web 控制台运行的地方。这解释了您看到的错误消息和堆栈跟踪。每当您访问此地址 (*:8161) 处的代理的 Web 控制台时,都会引发异常。
To fix the problem, change the port number to the port on which the ActiveMQ TCP transport is listening. I hazard a guess that it is probably the default port number of 61616
要解决此问题,请将端口号更改为 ActiveMQ TCP 传输正在侦听的端口。我猜测可能是默认端口号 61616
回答by mattias
I think the following is the fault:
我认为以下是错误:
<value>tcp://**:8161</value>
in your xml.
在你的 xml 中。
Make sure to put the actual address there.
确保将实际地址放在那里。
回答by user3078881
Just for who, like me, had got the same error even if brokerURLwas set correctly. Check the usage of the ProducerTemplateclass: in my code, for example, I missed the ExchangePatternparameter in the sendBodymethod of the producer.
对于像我这样的人来说,即使brokerURL设置正确,也会遇到同样的错误。检查ProducerTemplate类的用法:例如在我的代码中,我错过了生产者的sendBody方法中的ExchangePattern参数。
Hope this help
希望这有帮助