3
我现在开始了JMS一周。我使用Netbeans,maven和glassfish创建了JMS。对一个主题的JMS多次持久订阅
我一个生产者和一个耐用消费品,我想另一个耐用消费品添加到同一话题(不排队)。是否有可能这样做? ,因为我希望所有消费者都消费生产者发送的所有消息,无论消费者是否脱机。
有什么建议吗? 感谢
public class DurableReceive {
@Resource(lookup = "jms/myDurableConnectionFactory")
private static ConnectionFactory connectionFactory;
@Resource(lookup = "jms/myNewTopic")
private static Topic topic;
public static void main(String[] args) {
Destination dest = (Destination) topic;
JMSConsumer consumer;
boolean messageReceived = false;
String message;
System.out.println("Waiting for messages...");
try (JMSContext context = connectionFactory.createContext();) {
consumer = context.createDurableConsumer(topic, "Subscriber1");
while (!messageReceived) {
message = consumer.receiveBody(String.class);
if (message != null) {
System.out.print("Received the following message: " + message);
System.out.println("(Received date: " + new Date() + ")\n");
} else {
messageReceived = true;
}
}
} catch (JMSRuntimeException e) {
System.err.println("@#$%RuntimeException occurred: " + e.toString());
System.exit(1);
}
}
}
你能指导我吗? – 2014-09-19 05:00:23
您使用哪种框架与JMS提供程序进行连接? – dk14 2014-09-19 05:05:52
我真的不知道什么框架,但我猜它的java jdk? – 2014-09-19 05:15:09