1

我正在尝试通过 http 将我的 java 客户端应用程序连接到 ActiveMQ,但不断收到错误消息:(底部的完整错误)

javax.jms.JMSException: Could not post command: ProducerInfo 
No such field org.apache.activemq.command.ProducerInfo.sentCount

还有就是连接到ActiveMQ,因为服务端也报错了:(底部完全报错)

com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field 
org.apache.activemq.command.ProducerInfo.sentCount

是否存在库或 jar 问题?

这个连接有效我连接的原因:tcp://localhost:61616

活动MQ.xml

<broker>
  ...
  <transportConnectors>
    <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="http" uri="http://0.0.0.0:8081"/>
  </transportConnectors>
  ...
</broker>

我的 Java 客户端程序中的 jndi.properties:

java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
#java.naming.provider.url = tcp://localhost:61616
java.naming.provider.url = http://localhost:8081
connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry
queue.testQueue = testQueue

Java 客户端

package be.jmshub.jmsremotejndiproducer;

import javax.jms.JMSException;
import javax.jms.Connection;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.naming.Context;
import javax.naming.InitialContext;

public class Producer {

    public static void main(String[] args) throws JMSException {

        System.out.println("JMS REMOTE PRODUCER: start");

        try {
            // create a new intial context, which loads from jndi.properties file
            Context ctx = new InitialContext();
            QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("connectionFactory");
            Connection connection = factory.createConnection();
            Queue queue = (javax.jms.Queue) ctx.lookup("testQueue");
            Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);

            MessageProducer producer = session.createProducer(queue);

            System.out.println("JMS REMOTE PRODUCER: connected");

            int count = 0;

            for (int i = 0; i < 5; i++) {
                String messageText = "This is message " + (i + 1);
                Message message = session.createTextMessage(messageText);
                System.out.println("JMS REMOTE PRODUCER: sending - " + messageText);
                producer.send(message);
                count += 1;
            }
            System.out.println("JMS REMOTE PRODUCER: total messages sent: " + count);

            // Clean up
            session.close();
            connection.close();
        } catch (Exception ex) {
            System.out.println("JMS REMOTE PRODUCER: EXCEPTION:" + ex.toString());
        }
        System.out.println("JMS REMOTE PRODUCER: finished");
    }
}

这适用于 tcp://localhost:61616 但不适用于http://localhost:8080

任何人都可以帮助我启动并运行这件事吗?

客户端错误:

javax.jms.JMSException: Could not post command: ProducerInfo 
{commandId = 4, responseRequired = true, producerId = ID:pc-prd0170-57061-1434012164882-2:1:1:1, destination = queue://testQueue, brokerPath = null, dispatchAsync = false, windowSize = 0, sentCount = 0}
due to: java.io.IOException: Failed to post command: ProducerInfo
{commandId = 4, responseRequired = true, producerId = ID:pc-prd0170-57061-1434012164882-2:1:1:1, destination = queue://
testQueue, brokerPath = null, dispatchAsync = false, windowSize = 0, sentCount = 0}
as response was: HTTP/1.1 500 No such field org.apache.activemq.command.ProducerInfo.sentCount
---- Debugging information ---- 
field               : sentCount
class               : org.apache.activemq.command.ProducerInfo
required-type       : org.apache.activemq.command.ProducerInfo
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                :/org.apache.activemq.command.ProducerInfo/sentCount
line number         : 15
version             : null
------------------------------- 
[Cache-Control: must-revalidate,no-cache,no-store, Content-Type: text/html;charset=ISO-8859-1, Content-Length: 2251, Server: Jetty(7.6.7.v20120910)] org.apache.http.conn.BasicManagedEntity@1c222ae

服务器活动 MQ:

WARN | /
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field org.apache.activemq.command.ProducerInfo.sentCount
---- Debugging information ----
field               : sentCount
class               : org.apache.activemq.command.ProducerInfo
required-type       : org.apache.activemq.command.ProducerInfo
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /org.apache.activemq.command.ProducerInfo/sentCount
line number         : 15
version             : null
-------------------------------
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.determineType(AbstractReflectionConverter.java:453)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:294)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
        at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
        at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
        at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1058)
        at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1042)
        at com.thoughtworks.xstream.XStream.fromXML(XStream.java:913)
        at org.apache.activemq.transport.xstream.XStreamWireFormat.unmarshalText(XStreamWireFormat.java:57)
        at org.apache.activemq.transport.http.HttpTunnelServlet.doPost(HttpTunnelServlet.java:127)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:652)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:447)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
        at org.eclipse.jetty.server.handler.GzipHandler.handle(GzipHandler.java:275)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1040)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:374)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:972)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
        at org.eclipse.jetty.server.Server.handle(Server.java:363)
        at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:483)
        at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:931)
        at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:992)
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
        at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
        at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
        at java.lang.Thread.run(Thread.java:745)
4

1 回答 1

2

我猜你正在混合不同的 ActiveMQ 版本/包装,其中之一是5.9.0(或之前)。该字段sentCount从 version 开始存在5.9.1

  • 版本5.9.0于 2013 年 10 月 14 日发布
  • 该字段sentCount于 2013 年 12 月 3 日添加
于 2015-06-11T10:13:22.163 回答