tobby48 5 years ago
parent
commit
2d35ef1a17

+ 13
- 0
pom.xml View File

@@ -220,6 +220,19 @@
220 220
 			<version>2.9.0</version>
221 221
 		</dependency>
222 222
 		
223
+		<!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client -->
224
+		<dependency>
225
+		    <groupId>com.rabbitmq</groupId>
226
+		    <artifactId>amqp-client</artifactId>
227
+		    <version>5.7.3</version>
228
+		</dependency>
229
+
230
+		<dependency>
231
+			<groupId>org.elasticsearch</groupId>
232
+			<artifactId>elasticsearch</artifactId>
233
+			<version>1.7.6</version>
234
+		</dependency>
235
+	
223 236
 	</dependencies>
224 237
 	
225 238
 	<build>

+ 49
- 0
src/main/java/kr/co/swh/lecture/opensource/elasticsearch/App.java View File

@@ -0,0 +1,49 @@
1
+package kr.co.swh.lecture.opensource.elasticsearch;
2
+
3
+import java.io.IOException;
4
+import java.util.Date;
5
+
6
+import org.elasticsearch.ElasticsearchException;
7
+import org.elasticsearch.action.delete.DeleteResponse;
8
+import org.elasticsearch.action.get.GetResponse;
9
+import org.elasticsearch.action.index.IndexResponse;
10
+import org.elasticsearch.client.Client;
11
+import org.elasticsearch.client.transport.TransportClient;
12
+import org.elasticsearch.common.settings.ImmutableSettings;
13
+import org.elasticsearch.common.settings.Settings;
14
+import org.elasticsearch.common.transport.InetSocketTransportAddress;
15
+import org.elasticsearch.node.Node;
16
+import org.elasticsearch.node.NodeBuilder;
17
+
18
+import static org.elasticsearch.node.NodeBuilder.*;
19
+import static org.elasticsearch.common.xcontent.XContentFactory.*;
20
+
21
+public class App {
22
+
23
+	public static void main(String[] args) {
24
+		Settings settings = ImmutableSettings.settingsBuilder()
25
+				.put("cluster.name", "elasticsearch")
26
+				.build();
27
+		TransportClient client = new TransportClient(settings)
28
+		.addTransportAddress(new InetSocketTransportAddress("dev-swh.ga", 9300));
29
+
30
+		IndexResponse index_response = null;
31
+		try {
32
+			index_response = client.prepareIndex("twitter", "tweet", "1")
33
+			        .setSource(jsonBuilder()
34
+			                    .startObject()
35
+			                        .field("user", "kimchy")
36
+			                        .field("postDate", new Date())
37
+			                        .field("message", "trying out Elasticsearch")
38
+			                    .endObject()
39
+			                  )
40
+			        .execute()
41
+			        .actionGet();
42
+		} catch (ElasticsearchException e) {
43
+			e.printStackTrace();
44
+		} catch (IOException e) {
45
+			e.printStackTrace();
46
+		}
47
+		client.close();;
48
+	}
49
+}

+ 3
- 3
src/main/java/kr/co/swh/lecture/opensource/jsoup/news/NaverNewsCrawlSource.java View File

@@ -75,8 +75,8 @@ public class NaverNewsCrawlSource
75 75
 	public void init() {
76 76
 		domain = "naver";
77 77
 		category = new String[]{"politics"};
78
-		startDate = "20191019";
79
-		endDate = "20191020";
78
+		startDate = "20191117";
79
+		endDate = "20191117";
80 80
 		fastMode = false;
81 81
 		service = new NaverCrawlManager(domain, startDate, endDate, category, fastMode);
82 82
 		
@@ -91,7 +91,7 @@ public class NaverNewsCrawlSource
91 91
 	public static void main(String[] args) {
92 92
 		
93 93
 		NaverNewsCrawlSource source = new NaverNewsCrawlSource();
94
-//		source.init();
94
+		source.init();
95 95
 		System.out.println(NaverCrawlManager.totalDayFromCalendar(2019,10,20));
96 96
 		System.out.println(NaverCrawlManager.endDayFromTotalDay(2019,10));
97 97
 //		System.out.println(StringUtils.leftPad(String.valueOf(1), 2, "0"));

+ 28
- 0
src/main/java/kr/co/swh/lecture/opensource/rabbitmq/Publisher.java View File

@@ -0,0 +1,28 @@
1
+package kr.co.swh.lecture.opensource.rabbitmq;
2
+
3
+import java.io.IOException;
4
+import java.util.concurrent.TimeoutException;
5
+
6
+import com.rabbitmq.client.Channel;
7
+import com.rabbitmq.client.Connection;
8
+import com.rabbitmq.client.ConnectionFactory;
9
+
10
+public class Publisher {
11
+
12
+	private final static String QUEUE_NAME = "hello";
13
+
14
+	public static void main(String[] args) throws IOException, TimeoutException {
15
+		ConnectionFactory factory = new ConnectionFactory();
16
+		factory.setHost("dev-swh.ga");
17
+		Connection connection = factory.newConnection();
18
+		Channel channel = connection.createChannel();
19
+
20
+		channel.queueDeclare(QUEUE_NAME, false, false, false, null);
21
+		String message = "Hello World!";
22
+		channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
23
+		System.out.println(" [x] Sent '" + message + "'");
24
+
25
+		channel.close();
26
+		connection.close();
27
+	}
28
+}

+ 31
- 0
src/main/java/kr/co/swh/lecture/opensource/rabbitmq/Receiver.java View File

@@ -0,0 +1,31 @@
1
+package kr.co.swh.lecture.opensource.rabbitmq;
2
+
3
+import java.io.IOException;
4
+import java.util.concurrent.TimeoutException;
5
+import com.rabbitmq.client.AMQP;
6
+import com.rabbitmq.client.Channel;
7
+import com.rabbitmq.client.Connection;
8
+import com.rabbitmq.client.ConnectionFactory;
9
+import com.rabbitmq.client.Consumer;
10
+import com.rabbitmq.client.DefaultConsumer;
11
+import com.rabbitmq.client.Envelope;
12
+public class Receiver {
13
+	private final static String QUEUE_NAME = "hello";
14
+	public static void main(String[] argv) throws IOException, TimeoutException {
15
+		ConnectionFactory factory = new ConnectionFactory();
16
+		factory.setHost("dev-swh.ga");
17
+		Connection connection = factory.newConnection();
18
+		Channel channel = connection.createChannel();
19
+		channel.queueDeclare(QUEUE_NAME, false, false, false, null);
20
+		System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
21
+		Consumer consumer = new DefaultConsumer(channel) {
22
+			@Override
23
+			public void handleDelivery(String consumerTag, Envelope envelope,
24
+					AMQP.BasicProperties properties, byte[] body) throws IOException {
25
+				String message = new String(body, "UTF-8");
26
+				System.out.println(" [x] Received '" + message + "'");
27
+			}
28
+		};
29
+		channel.basicConsume(QUEUE_NAME, true, consumer);
30
+	}
31
+}