-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleUrlsRaw.java
71 lines (59 loc) · 2.46 KB
/
ExampleUrlsRaw.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.stomp.Frame;
import io.vertx.ext.stomp.StompClient;
import io.vertx.ext.stomp.StompClientConnection;
import io.vertx.ext.stomp.StompClientOptions;
public class ExampleUrlsRaw {
public static final String SERVER = "stream.abusix.net:61612";
public static final boolean SSL = true;
public static final String CREDENTIALS = "<user>:<pass>";
public static final String TOPIC = "<topic>";
public static final SimpleDateFormat OUTPUT_FILE_FORMAT = new SimpleDateFormat("'filtered'/yyyy-MM-dd/HH.'txt'");
public static void onMessage(Frame frame) {
Path target = Path.of(OUTPUT_FILE_FORMAT.format(new Date()));
if (!target.getParent().toFile().exists()) {
target.getParent().toFile().mkdirs();
}
try {
Files.write(target, (frame.getBody() + "\n").getBytes(),
StandardOpenOption.APPEND, StandardOpenOption.CREATE);
} catch (IOException e) {
System.err.println("Could not write file.");
e.printStackTrace();
}
}
public static void listen() {
StompClientOptions options = new StompClientOptions();
options.setHeartbeat(new JsonObject().put("x", 10000).put("y", 10000));
options.setHost(SERVER.split(":")[0]);
options.setPort(Integer.parseInt(SERVER.split(":")[1]));
options.setSsl(SSL);
options.setLogin(CREDENTIALS.split(":")[0]);
options.setPasscode(CREDENTIALS.split(":")[1]);
StompClient client = StompClient.create(Vertx.vertx(), options);
client.connect(ar -> {
if (ar.succeeded()) {
StompClientConnection conn = ar.result();
Map<String, String> headers = new HashMap<>();
headers.put("id", "1234"); // something unique
// To disable load-balancing (shared subscriptions):
//headers.put("channel", CREDENTIALS.split(":")[0] + "something_unique");
// Subscribe to topic
conn.subscribe(TOPIC, headers, ExampleUrlsRaw::onMessage);
}
});
client.close();
}
public static void main(String[] args) {
listen();
}
}