小弟是刚刚学习activemq,从官网下载了5.7.0,启动了amq后运行了demo里面chat,然后自己建了个工程,引入了activemq-all-5.7.0.jar,activemq-core-5.7.0.jar等包,按照demo里面的写法写了如下:
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/amq_jquery_adapter.js"></script>
<script type="text/javascript" src="js/amq.js"></script>
<script type="text/javascript">
var amq = org.activemq.Amq;
var chatTopic = 'topic://CHAT.DEMO';
var chatArea=null;
$(document).ready(function(){
org.activemq.Amq.init({ uri: 'amq', logging: true, timeout: 45, clientId:(new Date()).getTime().toString() });
chatArea=document.getElementById('txtContent');
$('#btnJoin').click(function(){
amq.addListener('chat', chatTopic, chatHandler);
amq.sendMessage(chatTopic, '<message type="join" from="' + $('#txtUser').val() + '"/>');
})
})
function chatHandler(message){
var type = message.getAttribute('type');
var from = message.getAttribute('from');
switch (type) {
case 'join' : {
chatArea.innerText += from + 'has joined the room!';
break;
}
}
}
<div>
<label>聊天记录</label>
<textarea id="txtContent" style="width: 300px;height: 100px;" rows="4" cols="4"></textarea>
</div>
<div>
<input id="txtUser" type="text"/>
<button id="btnJoin" type="button">进入</button>
</div>
现在出现的问题是,点击进入按钮,要么是chatHandler根本没有回应,要么是等个3,4秒chatHandler才响应。请问哪位大拿帮指点一下,愁死我了!!
------解决方案--------------------
似乎少了一个包?鉴定完毕