ActiveMQ setup - Unable to send the message to Queue (error - java.io.IOException: Unknown data type: 47)
Asked Answered
H

4

10

I have installed ActiveMQ and could access the url at - http://localhost:8161/admin/queues.jsp. When I try to drop a message to a queue I am getting the below error.

The sample code is given below:

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:

<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>

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)
Helfand answered 15/11, 2014 at 16:42 Comment(1)
stackoverflow showed me some error when I typed 'localhost' when I type the question. so ** in url is not a problemHelfand
R
32

The 'Unknown data type: 47' error is due to the configuration you are using for the following broker URL:

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

The problem is that the port number is incorrect. Port 8161 is where the embedded ActiveMQ web server runs, and therefore where you can access the web console. 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.

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.

Ruminant answered 15/11, 2014 at 16:49 Comment(2)
stackoverflow showed me some error when I typed 'localhost' when I type the question.Helfand
correct information you have provided to short out the problemCormophyte
C
1

I think the following is the fault:

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

in your xml.

Make sure to put the actual address there.

Coralloid answered 15/11, 2014 at 16:48 Comment(1)
stackoverflow showed me some error when I typed 'localhost' when I type the question.Helfand
G
1

Just for who, like me, had got the same error even if brokerURL was set correctly. Check the usage of the ProducerTemplate class: in my code, for example, I missed the ExchangePattern parameter in the sendBody method of the producer.

Hope this help

Guacharo answered 30/11, 2015 at 16:10 Comment(0)
I
0

By default, 8161 is http port while for tcp port is 61616. Check the logs of active mq for correct port.

 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/
Interrelated answered 15/5, 2021 at 13:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.