-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendReceiveMapMessage.java
More file actions
54 lines (45 loc) · 1.71 KB
/
SendReceiveMapMessage.java
File metadata and controls
54 lines (45 loc) · 1.71 KB
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
48
49
50
51
52
53
54
package com.topic;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
public class SendReceiveMapMessage {
/**
* @param args
*/
static ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL);
static Connection connection = null;
public static void main(String[] args) {
new SendReceiveMapMessage().sendReceive();
}
private void sendReceive() {
MessageProducer messageProducer = null;
MessageConsumer consumer = null;
Session session = null;
Destination dest = null;
try {
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
dest = session.createTopic("Topics");
messageProducer = session.createProducer(dest);
consumer = session.createConsumer(dest,("intValue=5"));
MapMessage mapMessage = session.createMapMessage();
int i = 903684,intProperty = 5;
mapMessage.setInt("Value", i);
mapMessage.setIntProperty("intValue", intProperty);
messageProducer.send(mapMessage);
connection.start();
MapMessage map = (MapMessage) consumer.receive(100);
System.out.println("Message Received "+map.getInt("Value"));
System.out.println(" Boolean "+map.getBoolean("")+" double "+map.getDouble("d")+" byte "+map.getByte("")+" "+map.getInt("Value"));
} catch (JMSException e) {
e.printStackTrace();
}
}
}