JMS 创建连接报错 本帖最后由 hanjiaming 于 2012-07-27 16:43:20 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 代码如下:Comsumerpublic class Comsumer { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String user = ActiveMQConnection.DEFAULT_USER; String password = ActiveMQConnection.DEFAULT_PASSWORD; String url = ActiveMQConnection.DEFAULT_BROKER_URL;// String url="vm:(broker:(tcp://localhost:61616))";// String url="vm://localhost"; String subject = "TOOL.DEFAULT"; ConnectionFactory connectionFactory = new ActiveMQConnectionFactory( user, password, url); Connection connection; try { connection = connectionFactory.createConnection(); connection.start(); final Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue(subject); MessageConsumer message = session.createConsumer(destination); message.setMessageListener(new MessageListener() { public void onMessage(Message msg) { MapMessage message = (MapMessage) msg; try { System.out.println("--收到消息:" + new Date(message.getLong("count"))); session.commit(); } catch (JMSException e) { e.printStackTrace(); } } }); Thread.sleep(30000); session.close(); connection.close(); } catch (JMSException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }}Producer:public class Producer { public static void main(String[] args) { String user = ActiveMQConnection.DEFAULT_USER; String password = ActiveMQConnection.DEFAULT_PASSWORD; String url = ActiveMQConnection.DEFAULT_BROKER_URL;// String url="vm:(broker:(tcp://localhost:61616))";// String url = "tcp://localhost:61616";// String url="vm://localhost"; String subject = "TOOL.DEFAULT"; ConnectionFactory contectionFactory = new ActiveMQConnectionFactory( user, password, url); try { Connection connection = contectionFactory.createConnection(); connection.start(); Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue(subject); MessageProducer producer = session.createProducer(destination); for (int i = 0; i <= 20; i++) { MapMessage message = session.createMapMessage(); Date date = new Date(); message.setLong("count", date.getTime()); Thread.sleep(1000); producer.send(message); System.out.println("--发送消息:" + date); } session.commit(); session.close(); connection.close(); } catch (JMSException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }} 楼主解决问题了吗?貌似是没开activemq.bat的原因吧 登录后刷新,重复登录的问题 关于日期函数问题 如何对MAP关联进行查询 想买二手路由器2个,作毕业设计实验用! 求助一个反射类,请发到我的油箱,谢谢 XML的数据压缩方面的资料,我现在急需,无限感激!!! weblogic和websphere那个好一点啊? 装了jdk1。3之后如何构建电子商务的网站 高手帮忙看看!急,在线等待!一个画图程序,根据坐标点画矩形,但神秘失效 IBM vaj ejb问题 javaEE开发为什么要用到DTO层 JNative 调用dll的问题
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String user = ActiveMQConnection.DEFAULT_USER;
String password = ActiveMQConnection.DEFAULT_PASSWORD;
String url = ActiveMQConnection.DEFAULT_BROKER_URL;
// String url="vm:(broker:(tcp://localhost:61616))";
// String url="vm://localhost";
String subject = "TOOL.DEFAULT";
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory( user, password, url);
Connection connection;
try {
connection = connectionFactory.createConnection();
connection.start();
final Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(subject);
MessageConsumer message = session.createConsumer(destination);
message.setMessageListener(new MessageListener() {
public void onMessage(Message msg) {
MapMessage message = (MapMessage) msg;
try {
System.out.println("--收到消息:" + new Date(message.getLong("count")));
session.commit();
} catch (JMSException e) {
e.printStackTrace();
}
}
});
Thread.sleep(30000);
session.close();
connection.close();
} catch (JMSException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} }}Producer:public class Producer {
public static void main(String[] args) {
String user = ActiveMQConnection.DEFAULT_USER;
String password = ActiveMQConnection.DEFAULT_PASSWORD;
String url = ActiveMQConnection.DEFAULT_BROKER_URL;
// String url="vm:(broker:(tcp://localhost:61616))";
// String url = "tcp://localhost:61616";
// String url="vm://localhost";
String subject = "TOOL.DEFAULT";
ConnectionFactory contectionFactory = new ActiveMQConnectionFactory(
user, password, url);
try {
Connection connection = contectionFactory.createConnection();
connection.start();
Session session = connection.createSession(Boolean.TRUE,
Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(subject);
MessageProducer producer = session.createProducer(destination);
for (int i = 0; i <= 20; i++) {
MapMessage message = session.createMapMessage();
Date date = new Date();
message.setLong("count", date.getTime());
Thread.sleep(1000);
producer.send(message);
System.out.println("--发送消息:" + date);
}
session.commit();
session.close();
connection.close();
} catch (JMSException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}