-
Notifications
You must be signed in to change notification settings - Fork 0
/
DurableSubscriber.java
47 lines (39 loc) · 1.27 KB
/
DurableSubscriber.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.topic;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
public class DurableSubscriber {
public void createDurableSubscriber(Destination topic, Connection connection){
try {
System.out.println("In Create() ->");
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createDurableSubscriber((Topic) topic, "Subscriber3","(mapMessage=true)",false);
while (true) {
Message message = consumer.receiveNoWait();
if (message != null) {
if (message instanceof TextMessage) {
System.out.println("> Message4 Received "
+ ((TextMessage) message).getText());
}
else if(message instanceof MapMessage){
System.out.println("> Message4 Received "
+ ((MapMessage) message).getInt("MIN_VALUE"));
}
} else {
System.out.println("Message is null!");
break;
}
}
consumer.close();
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}