我已使用ActiveMQ-Pub/Sub
和Java
实施了Stomp.js
计划。只有一个生成器用Java
编写,消费者用js
编写。
这是问题情景,
A
连接并订阅同一主题。B
连接并订阅同一主题。A
和B
同时收听同一主题,但A
收到的数据与B
收到的数据不同,B
会跳过一些数据。A
时,B
工作正常。B
时,A
工作正常。以下是制作人代码
public static Session SESSION;
/**
*
* @return @throws JMSException
*/
public static Session getSessionInstance() throws JMSException, IOException {
if (null == SESSION) {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(Context.getSystemProperties().getAmp().getUrl());
Connection connection = connectionFactory.createConnection();
connectionFactory.getPrefetchPolicy().setAll(1);
connection.start();
SESSION = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}
return SESSION;
}
/**
*
* @param message
* @throws JMSException
*/
public static void sendMessage(String topic, String message) throws JMSException, IOException {
Session session = getSessionInstance();
Destination destination = session.createQueue(topic);
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage txtMessage = session.createTextMessage(message);
producer.send(txtMessage);
producer.close();
}
和消费者
var client = Stomp.client("ws://localhost:61614?consumer.prefetchSize=1", "v11.stomp");
client.debug = null;
var selectedVehicleImei = 741852963123456;
client.connect("", "", function (topic) {
client.subscribe("COO." + selectedVehicleImei, function (message) {
var infodata = JSON.parse(message.body);
console.log(infodata);
})
})
我已尝试设置pre-fetch
值为,
在制作人,
connectionFactory.getPrefetchPolicy().setAll(1);
在消费者中,
?consumer.prefetchSize=1
但仍然没有运气,这里的问题是什么,谁能告诉我怎样才能让这项工作成功?
答案 0 :(得分:1)
我认为您需要使用createTopic而不是CreateQueue。即使您调用了变量主题,它看起来像是一个队列。
队列适用于只需要由一个消费者回答的任务(如发送电子邮件)。