initial commit
This commit is contained in:
commit
3e7357aba2
11 changed files with 248 additions and 0 deletions
15
aeron/publisher/Dockerfile
Normal file
15
aeron/publisher/Dockerfile
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
FROM eclipse-temurin:21-jdk
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
ENV JAVA_TOOL_OPTIONS="--add-opens=java.base/sun.nio.ch=ALL-UNNAMED"
|
||||
|
||||
ADD https://repo1.maven.org/maven2/io/aeron/aeron-all/1.44.1/aeron-all-1.44.1.jar aeron.jar
|
||||
ADD https://repo1.maven.org/maven2/org/agrona/agrona/1.18.1/agrona-1.18.1.jar agrona.jar
|
||||
|
||||
COPY Publisher.java .
|
||||
|
||||
RUN javac -cp "aeron.jar:agrona.jar" Publisher.java
|
||||
|
||||
CMD ["java", "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED", "-cp", ".:aeron.jar:agrona.jar", "Publisher"]
|
||||
49
aeron/publisher/Publisher.java
Normal file
49
aeron/publisher/Publisher.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import io.aeron.Aeron;
|
||||
import io.aeron.Publication;
|
||||
import io.aeron.driver.MediaDriver;
|
||||
import org.agrona.concurrent.UnsafeBuffer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class Publisher {
|
||||
public static void main(String[] args) throws Exception {
|
||||
MediaDriver driver = MediaDriver.launchEmbedded();
|
||||
|
||||
Aeron.Context ctx = new Aeron.Context()
|
||||
.aeronDirectoryName(driver.aeronDirectoryName());
|
||||
|
||||
Aeron aeron = Aeron.connect(ctx);
|
||||
|
||||
String channel = "aeron:udp?endpoint=subscriber:40123";
|
||||
int streamId = 1001;
|
||||
|
||||
Publication publication = aeron.addPublication(channel, streamId);
|
||||
UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(256));
|
||||
|
||||
long counter = 0;
|
||||
|
||||
System.out.println("Publisher ready");
|
||||
|
||||
while (true) {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String msg = counter + "," + timestamp;
|
||||
|
||||
buffer.setMemory(0, buffer.capacity(), (byte) 0);
|
||||
|
||||
byte[] bytes = msg.getBytes(StandardCharsets.UTF_8);
|
||||
buffer.putBytes(0, bytes);
|
||||
|
||||
long result;
|
||||
do {
|
||||
result = publication.offer(buffer, 0, bytes.length);
|
||||
if (result < 0)
|
||||
Thread.yield();
|
||||
} while (result < 0);
|
||||
|
||||
System.out.println("Sent: " + msg);
|
||||
counter++;
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue