tobby48 5 gadus atpakaļ
vecāks
revīzija
1d20d60f55

+ 0
- 39
src/main/java/kr/co/swh/lecture/opensource/rabbitmq/EmitLogTopic.java Parādīt failu

@@ -1,39 +0,0 @@
1
-package kr.co.swh.lecture.opensource.rabbitmq; 
2
-
3
-import com.rabbitmq.client.Channel;
4
-import com.rabbitmq.client.Connection;
5
-import com.rabbitmq.client.ConnectionFactory;
6
-
7
-/**
8
- * <pre>
9
- * kr.co.swh.lecture.opensource.rabbitmq 
10
- * EmitLogTopic.java
11
- *
12
- * 설명 :
13
- * </pre>
14
- * 
15
- * @since : 2020. 6. 21.
16
- * @author : tobby48
17
- * @version : v1.0
18
- */
19
-public class EmitLogTopic {
20
-
21
-  private static final String EXCHANGE_NAME = "news.new";
22
-
23
-  public static void main(String[] argv) throws Exception {
24
-    ConnectionFactory factory = new ConnectionFactory();
25
-    factory.setHost("dev-swh.ga");
26
-    try (Connection connection = factory.newConnection();
27
-         Channel channel = connection.createChannel()) {
28
-
29
-        channel.exchangeDeclare(EXCHANGE_NAME, "topic");
30
-
31
-        String routingKey = "naver";
32
-        String message = "뉴스다";
33
-
34
-        channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes("UTF-8"));
35
-        System.out.println(" [x] Sent '" + routingKey + "':'" + message + "'");
36
-    }
37
-  }
38
-  //..
39
-}

src/main/java/kr/co/swh/lecture/opensource/rabbitmq/ReceiveLogsTopic.java → src/main/java/kr/co/swh/lecture/opensource/rabbitmq/TopicReceiver.java Parādīt failu

@@ -15,7 +15,7 @@ import java.io.IOException;
15 15
  * @author : tobby48
16 16
  * @version : v1.0
17 17
  */
18
-public class ReceiveLogsTopic {
18
+public class TopicReceiver {
19 19
 	
20 20
 	private static final String EXCHANGE_NAME = "news.new";
21 21
 	
@@ -30,11 +30,7 @@ public class ReceiveLogsTopic {
30 30
 		channel.exchangeDeclare(EXCHANGE_NAME, "topic");
31 31
 		String queueName = channel.queueDeclare().getQueue();
32 32
 		
33
-		String[] bindingKeys = {"naver", "daum"};
34
-		
35
-		for (String bindingKey : bindingKeys) {
36
-			channel.queueBind(queueName, EXCHANGE_NAME, bindingKey);
37
-		}
33
+		channel.queueBind(queueName, EXCHANGE_NAME, "naverKey");
38 34
 		
39 35
 		System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
40 36
 		

+ 37
- 0
src/main/java/kr/co/swh/lecture/opensource/rabbitmq/TopicSender.java Parādīt failu

@@ -0,0 +1,37 @@
1
+package kr.co.swh.lecture.opensource.rabbitmq; 
2
+
3
+import com.rabbitmq.client.Channel;
4
+import com.rabbitmq.client.Connection;
5
+import com.rabbitmq.client.ConnectionFactory;
6
+
7
+/**
8
+ * <pre>
9
+ * kr.co.swh.lecture.opensource.rabbitmq 
10
+ * TopicSender.java
11
+ *
12
+ * 설명 :
13
+ * </pre>
14
+ * 
15
+ * @since : 2020. 6. 21.
16
+ * @author : tobby48
17
+ * @version : v1.0
18
+ */
19
+public class TopicSender {
20
+
21
+	private static final String EXCHANGE_NAME = "news.new";
22
+
23
+	public static void main(String[] argv) throws Exception {
24
+		ConnectionFactory factory = new ConnectionFactory();
25
+		factory.setHost("dev-swh.ga");
26
+		Connection connection = factory.newConnection();
27
+		Channel channel = connection.createChannel();
28
+		channel.exchangeDeclare(EXCHANGE_NAME, "topic");
29
+
30
+		String routingKey = "naverKey";
31
+		String message = "뉴스다";
32
+
33
+		channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes("UTF-8"));
34
+		System.out.println(" [x] Sent '" + routingKey + "':'" + message + "'");
35
+	}
36
+	//..
37
+}