Created
February 18, 2022 12:50
-
-
Save io7m/6259d0b67a4faafbbc0ca4ee47990b1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.io7m.jmstest; | |
import com.io7m.jmulticlose.core.CloseableCollection; | |
import org.apache.activemq.artemis.api.core.TransportConfiguration; | |
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; | |
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory; | |
import java.util.UUID; | |
import static javax.jms.Session.CLIENT_ACKNOWLEDGE; | |
import static org.apache.activemq.artemis.api.jms.JMSFactoryType.CF; | |
public final class Main | |
{ | |
private Main() | |
{ | |
} | |
public static void main( | |
final String[] args) | |
throws Exception | |
{ | |
try (var resources = CloseableCollection.create()) { | |
final var transportConfiguration = | |
new TransportConfiguration(NettyConnectorFactory.class.getName()); | |
final var connections = | |
resources.add(ActiveMQJMSClient.createConnectionFactoryWithoutHA( | |
CF, | |
transportConfiguration)); | |
connections.setBrokerURL("tcp://<redacted>"); | |
connections.setClientID(UUID.randomUUID().toString()); | |
connections.setUser("<redacted>"); | |
connections.setPassword("<redacted>"); | |
final var topicConnection = | |
resources.add(connections.createTopicConnection()); | |
final var session = | |
resources.add(topicConnection.createTopicSession( | |
false, | |
CLIENT_ACKNOWLEDGE)); | |
final var topic = | |
session.createTopic("<redacted>"); | |
final var subscriber = | |
resources.add(session.createSubscriber(topic)); | |
topicConnection.start(); | |
while (true) { | |
subscriber.receive(1_000L); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment