-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProdAndConsWithML.java
43 lines (34 loc) · 1.36 KB
/
ProdAndConsWithML.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
package com.queue;
import java.util.Date;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
public class ProdAndConsWithML {
public static void main(String[] args) {
Connection connection = null;
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_URL);
try {
connection = connectionFactory.createConnection();
System.out.println("Connection created");
Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("Queue");
MessageProducer messageProducer = session.createProducer(destination);
MessageConsumer consumer = session.createConsumer(destination);
connection.start();
messageProducer.send(session.createTextMessage("Hi!"+new Date()));
System.out.println("Message sent! ");
TextMessage message = (TextMessage) consumer.receive();
System.out.println("Message received! " + message.getText());
connection.close();
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}