我尝试编写一个简单的Ajax客户端来发送和接收消息。它已成功部署,但我从未收到客户端的消息。我正在努力思考我所缺少的东西,但仍然无法使其发挥作用。
这是我的代码:
在以下地址收听连接:tcp:// lilyubuntu:61616
信息|连接器openwire开始
信息| ActiveMQ JMS Message Broker(localhost,ID:lilyubuntu-56855-1272317001405-0:0)开始了
信息|通过org.mortbay.log.Slf4jLog登录org.slf4j.impl.JCLLoggerAdapter(org.mortbay.log)
信息|码头-6.1.9
信息| ActiveMQ WebConsole已初始化。
信息|初始化Spring FrameworkServlet'调度程序' 信息| http://0.0.0.0:8161/admin的ActiveMQ控制台 信息|初始化Spring root WebApplicationContext
信息|连接器vm:// localhost已启动
信息|骆驼控制台http://0.0.0.0:8161/camel
信息| ActiveMQ网络演示http://0.0.0.0:8161/demo 信息| http://0.0.0.0:8161/fileserver上的RESTful文件访问应用程序 信息|已启动SelectChannelConnector@0.0.0.0:8161
3)index.xml,它是测试客户端的html:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="amq/amq.js"></script>
<script type="text/javascript">amq.uri='amq';</script>
<title>Hello Ajax ActiveMQ</title>
</head>
<body>
<p>Hello World!</p>
<script type="text/javascript">
amq.sendMessage("topic://myDetector", "message");
var myHandler =
{
rcvMessage: function(message)
{
alert("received "+message);
}
};
function myPoll(first)
{
if (first)
{
amq.addListener('myDetector', 'topic://myDetector', myHandler.rcvMessage);
}
}
amq.addPollHandler(myPoll);
4)Web.xml:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
- &GT;
<display-name>ActiveMQ Web Demos</display-name>
<description>
Apache ActiveMQ Web Demos
</description>
<!-- context config -->
<context-param>
<param-name>org.apache.activemq.brokerURL</param-name>
<param-value>vm://localhost</param-value> (I also tried tcp://localhost:61616)
<description>The URL of the Message Broker to connect to</description>
</context-param>
<context-param>
<param-name>org.apache.activemq.embeddedBroker</param-name>
<param-value>true</param-value>
<description>Whether we should include an embedded broker or not</description>
</context-param>
<!-- servlet mappings -->
<!-- the subscription REST servlet -->
<servlet>
<servlet-name>AjaxServlet</servlet-name>
<servlet-class>org.apache.activemq.web.AjaxServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>MessageServlet</servlet-name>
<servlet-class>org.apache.activemq.web.MessageServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<!--
Uncomment this parameter if you plan to use multiple consumers over REST
<init-param>
<param-name>destinationOptions</param-name>
<param-value>consumer.prefetchSize=1</param-value>
</init-param>
-->
</servlet>
<!-- the queue browse servlet -->
<filter>
<filter-name>session</filter-name>
<filter-class>org.apache.activemq.web.SessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>session</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
在所有这些之后,我部署了网络应用程序,并且它已成功部署,但是当我在http://localhost:8080/ActiveMQAjaxService/index.html中尝试时,没有任何反应。
我可以在http://localhost:8161/demo/portfolio/portfolio.html成功运行demo portfolioPublisher演示,并查看始终更新的数字。但对于我简单的网络应用程序,没有什么真正有效。
欢迎任何建议/提示。非常感谢
莉莉答案 0 :(得分:1)
尝试进入管理层web console;网页,并查看您是否可以从该上下文向您的经纪人发送消息,这可能会指导您解决问题。
答案 1 :(得分:0)
我在网络应用程序中设置了web.xml
如下,它可以正常工作。
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>msg_tomcat_activemq</display-name>
<context-param>
<param-name>org.apache.activemq.brokerURL</param-name>
<param-value>tcp://192.168.1.105:61616</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>
</servlet>
<servlet>
<servlet-name>MessageServlet</servlet-name>
<servlet-class>org.apache.activemq.web.MessageServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AjaxServlet</servlet-name>
<url-pattern>/amq/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MessageServlet</servlet-name>
<url-pattern>/message/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>session</filter-name>
<filter-class>org.eclipse.jetty.continuation.ContinuationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>session</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.apache.activemq.web.SessionListener</listener-class>
</listener>
</web-app>