简体   繁体   English

ActiveMQ Servlet与Java客户端连接

[英]ActiveMQ servlet connect with java client

I'm trying to connect from Java to a running ActiveMQ servlet(on Weblogic 12), but I'm getting the following exception on conn.start(); 我正在尝试从Java连接到运行中的ActiveMQ servlet(在Weblogic 12上),但是在conn.start();上遇到了以下异常conn.start(); :

javax.jms.JMSException: Could not post command: ConnectionInfo {commandId = 1, responseRequired = true, connectionId = ID:lmdesetup-jab-38449-1378221016985-2:1, clientId = ID:lmdesetup-jab-38449-1378221016985-1:1, clientIp = null, userName = null, password = *****, brokerPath = null, brokerMasterConnector = false, manageable = true, clientMaster = true, faultTolerant = false, failoverReconnect = false} due to: java.io.IOException: Failed to post command: ConnectionInfo {commandId = 1, responseRequired = true, connectionId = ID:lmdesetup-jab-38449-1378221016985-2:1, clientId = ID:lmdesetup-jab-38449-1378221016985-1:1, clientIp = null, userName = null, password = *****, brokerPath = null, brokerMasterConnector = false, manageable = true, clientMaster = true, faultTolerant = false, failoverReconnect = false} as response was: HTTP/1.1 500 Internal Server Error [Connection: close, Date: Tue, 03 Sep 2013 15:11:02 GMT, Content-Length: 3092, Content-Type: text/html; charset=UTF-8, X-Powered-By: Servlet/3.0 JSP/2.2]
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:62)
at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1409)
at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1496)
at org.apache.activemq.ActiveMQConnection.start(ActiveMQConnection.java:524)

The code is here: 代码在这里:

QueueConnectionFactory factory = new ActiveMQConnectionFactory("http://localhost:8888/myApp/amq");
Connection conn = factory.createConnection();
conn.start();

(The code is based on this example: http://activemq.apache.org/hello-world.html ) (代码基于以下示例: http : //activemq.apache.org/hello-world.html

I'm quite sure the ActiveMQ broker and AjaxServlet are fine, because I can send and receive messages using js client. 我非常确定ActiveMQ代理和AjaxServlet很好,因为我可以使用js客户端发送和接收消息。

The servlet is defined like this in web.xml: servlet在web.xml中的定义如下:

<context-param>
    <param-name>org.apache.activemq.brokerURL</param-name>
    <param-value>vm://localhost</param-value>
</context-param>
<context-param>
    <param-name>org.apache.activemq.embeddedBroker</param-name>
    <param-value>true</param-value>
</context-param>
<servlet>
    <servlet-name>AjaxServlet</servlet-name>
    <servlet-class>org.apache.activemq.web.AjaxServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
</servlet>
    <servlet-mapping>
    <servlet-name>AjaxServlet</servlet-name>
    <url-pattern>/amq/*</url-pattern>
</servlet-mapping>
...

I have found someone wlse with the same problem, but the solution is not there: http://blog.gmane.org/gmane.comp.java.activemq.user/month=20090501 我发现有人遇到同样的问题,但解决方案不存在: http : //blog.gmane.org/gmane.comp.java.activemq.user/month=20090501

Here's the exception from Weblogic: 这是Weblogic的例外情况:

      ####<Sep 3, 2013 4:19:32 PM UTC> <Error> <Kernel> <mymachine> <myServer> <[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1378225172656> <BEA-000802> <ExecuteRequest failed
java.lang.IllegalStateException: Can NOT error at this state: AsyncCompleted.
java.lang.IllegalStateException: Can NOT error at this state: AsyncCompleted
at weblogic.servlet.internal.async.DefaultState.notifyError(AsyncStates.java:62)
 at weblogic.servlet.internal.async.AsyncContextImpl.handleError(AsyncContextImpl.java:125)
 at weblogic.servlet.internal.async.DispatchHandler.run(DispatchHandler.java:33)
 at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:545)
 at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
 at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
 >
 ####<Sep 3, 2013 4:19:32 PM UTC> <Error> <HTTP> <mymachine> <myServer> <[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1378225172779> <BEA-101020> <[ServletContext@1154401993[app:ino-all module:ino path:null spec-version:3.0]] Servlet failed with an Exception
     java.lang.UnsupportedOperationException: A destination must be specified.
     at org.apache.activemq.ActiveMQMessageProducer.send(ActiveMQMessageProducer.java:257)
     at org.apache.activemq.ActiveMQMessageProducer.send(ActiveMQMessageProducer.java:224)
     at org.apache.activemq.ActiveMQMessageProducerSupport.send(ActiveMQMessageProducerSupport.java:300)
     at org.apache.activemq.web.WebClient.send(WebClient.java:243)
     at org.apache.activemq.web.MessageListenerServlet.doPost(MessageListenerServlet.java:219)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:751)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
     at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242)
     at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:216)
     at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:132)
     at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:338)
     at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:74)
     at org.apache.activemq.web.SessionFilter.doFilter(SessionFilter.java:45)
     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:74)

I don't think you need to create an ActiveMQConnectionFactory in your Java client if you are going to try using the Ajax servlet. 如果您要尝试使用Ajax servlet,我认为不需要在Java客户端中创建ActiveMQConnectionFactory If you look at the javascript files bundled with the distribution, all the javascript is doing is constructing a POST request to put a message to a queue. 如果您查看与发行版捆绑在一起的javascript文件 ,则所有javascript都在构造POST请求以将消息放入队列。

If you look at the Client Sending messages section of the ActiveMQ Ajax docs it explains a little of what happens behind the scene. 如果您查看ActiveMQ Ajax文档的“ 客户端发送消息”部分,它将解释一些幕后发生的事情。 So I think if you want to use the AjaxServlet for your Java client you would need to construct a HttpServletRequest similar to the way the javascript is creating a XMLHttpRequest . 因此,我认为,如果您想将AjaxServlet用于Java客户端,则需要构造一个HttpServletRequest,类似于javascript创建XMLHttpRequest

Alternatively, If you want to follow the example that you linked to, I believe you would need to connect like this: 另外,如果您想遵循链接到的示例,我相信您需要像这样进行连接:

// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");

// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();

tcp://localhost:61616 should work because by default ActiveMQ adds a tcp connector on port 61616. tcp://localhost:61616应该可以工作,因为默认情况下 ActiveMQ在端口61616上添加了tcp连接器。

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

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