|
@@ -0,0 +1,61 @@
|
|
1
|
+package kr.co.swh.lecture.opensource.activemq;
|
|
2
|
+
|
|
3
|
+import javax.jms.Connection;
|
|
4
|
+import javax.jms.ConnectionFactory;
|
|
5
|
+import javax.jms.Destination;
|
|
6
|
+import javax.jms.JMSException;
|
|
7
|
+import javax.jms.MessageProducer;
|
|
8
|
+import javax.jms.Session;
|
|
9
|
+import javax.jms.TextMessage;
|
|
10
|
+
|
|
11
|
+import org.apache.activemq.ActiveMQConnection;
|
|
12
|
+import org.apache.activemq.ActiveMQConnectionFactory;
|
|
13
|
+/**
|
|
14
|
+ * <pre>
|
|
15
|
+ * kr.co.swh.lecture.opensource.activemq
|
|
16
|
+ * MessageSender.java
|
|
17
|
+ *
|
|
18
|
+ * 설명 :
|
|
19
|
+ * </pre>
|
|
20
|
+ *
|
|
21
|
+ * @since : 2020. 6. 14.
|
|
22
|
+ * @author : tobby48
|
|
23
|
+ * @version : v1.0
|
|
24
|
+ */
|
|
25
|
+public class MessageSender {
|
|
26
|
+
|
|
27
|
+ //URL of the JMS server. DEFAULT_BROKER_URL will just mean that JMS server is on localhost
|
|
28
|
+// private static String url = ActiveMQConnection.DEFAULT_BROKER_URL;
|
|
29
|
+ private static String url = "tcp://192.168.0.14:61616";
|
|
30
|
+
|
|
31
|
+ // default broker URL is : tcp://localhost:61616"
|
|
32
|
+ private static String subject = "JCG_QUEUE"; // Queue Name.You can create any/many queue names as per your requirement.
|
|
33
|
+
|
|
34
|
+ public static void main(String[] args) throws JMSException {
|
|
35
|
+ // Getting JMS connection from the server and starting it
|
|
36
|
+ ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
|
|
37
|
+ Connection connection = connectionFactory.createConnection();
|
|
38
|
+ connection.start();
|
|
39
|
+
|
|
40
|
+ //Creating a non transactional session to send/receive JMS message.
|
|
41
|
+ Session session = connection.createSession(false,
|
|
42
|
+ Session.AUTO_ACKNOWLEDGE);
|
|
43
|
+
|
|
44
|
+ //Destination represents here our queue 'JCG_QUEUE' on the JMS server.
|
|
45
|
+ //The queue will be created automatically on the server.
|
|
46
|
+ Destination destination = session.createQueue(subject);
|
|
47
|
+
|
|
48
|
+ // MessageProducer is used for sending messages to the queue.
|
|
49
|
+ MessageProducer producer = session.createProducer(destination);
|
|
50
|
+
|
|
51
|
+ // We will send a small text message saying 'Hello World!!!'
|
|
52
|
+ TextMessage message = session
|
|
53
|
+ .createTextMessage("Hello !!! Welcome to the world of ActiveMQ.");
|
|
54
|
+
|
|
55
|
+ // Here we are sending our message!
|
|
56
|
+ producer.send(message);
|
|
57
|
+
|
|
58
|
+ System.out.println("JCG printing@@ '" + message.getText() + "'");
|
|
59
|
+ connection.close();
|
|
60
|
+ }
|
|
61
|
+}
|