initial commit
This commit is contained in:
commit
976b4f88cc
11 changed files with 249 additions and 0 deletions
22
natsio/publisher/Publisher.java
Normal file
22
natsio/publisher/Publisher.java
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import io.nats.client.Connection;
|
||||
import io.nats.client.Nats;
|
||||
import java.time.Duration;
|
||||
|
||||
public class Publisher {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Connection nc = Nats.connect("nats://nats:4222");
|
||||
|
||||
int counter = 0;
|
||||
|
||||
while (true) {
|
||||
long sendTime = System.currentTimeMillis();
|
||||
String msg = counter + "," + sendTime;
|
||||
nc.publish("demo.subject", msg.getBytes());
|
||||
nc.flush(Duration.ofSeconds(1));
|
||||
|
||||
System.out.println("Sent: " + counter);
|
||||
counter++;
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue