Using Qpid JMS
Using Qpid JMS Red Hat build of Apache Qpid JMS 2.4 Developing an AMQ messaging client using Jakarta
cd <project-dir> <repository> <id>red-hat-ga</id> <url>https://maven.repository.redhat.com/ga</url> </repository> <dependency> <groupId>org.apache.qpid</groupId> <artifactId>qpid-jms-client</artifactId> <version>2.4.0.redhat-00005</version> </dependency> unzip amq-clients-2.4.0-maven-repository.zip git clone https://github.com/apache/qpid-jms.git qpid-jms cd qpid-jms git checkout 2.4.0 mvn clean package dependency:copy-dependencies -DincludeScope=runtime -DskipTests java -cp "target/classes:target/dependency/*" org.apache.qpid.jms.example.HelloWorld > java -cp "target\classes;target\dependency\*" org.apache.qpid.jms.example.HelloWorld java -cp "target/classes/:target/dependency/*" org.apache.qpid.jms.example.HelloWorld Hello world! javax.naming.Context context = new javax.naming.InitialContext(); java.naming.factory.initial = org.apache.qpid.jms.jndi.JmsInitialContextFactory java -Djava.naming.factory.initial=org.apache.qpid.jms.jndi.JmsInitialContextFactory Hashtable<Object, Object> env = new Hashtable<>(); env.put("java.naming.factory.initial", "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); InitialContext context = new InitialContext(env); connectionFactory. <lookup-name> = <connection-uri> connectionFactory.app1 = amqp://example.net:5672?jms.clientID=backend ConnectionFactory factory = (ConnectionFactory) context.lookup("app1"); <scheme>://<host>:<port>[?<option>=<value>[&<option>=<value>...]] amqp://example.net:5672?jms.clientID=backend failover:(<connection-uri>[,<connection-uri>...])[?<option>=<value>[&<option>=<value>...]] failover:(amqp://host1:5672,amqp://host2:5672)?jms.clientID=backend queue. <lookup-name> = <queue-name> topic. <lookup-name> = <topic-name> queue.jobs = app1/work-items topic.notifications = app1/updates Queue queue = (Queue) context.lookup("jobs"); Topic topic = (Topic) context.lookup("notifications"); amqp://localhost:5672?jms.clientID=foo&transport.connectTimeout=30000 amqps://myhost.mydomain:5671 failover:(amqp://host1:5672,amqp://host2:5672)?jms.clientID=foo&failover.maxReconnectAttempts=20 failover:(amqp://host1:5672?amqp.option=value,amqp://host2:5672?transport.option=value)?jms.clientID=foo failover:(amqp://host1:5672,amqp://host2:5672)?jms.clientID=foo&failover.nested.amqp.vhost=myhost discovery:(<agent-uri>)?discovery.maxReconnectAttempts=20&discovery.discovered.jms.clientID=foo discovery:(file:///path/to/monitored-file?updateInterval=60000) discovery:(multicast://default?group=default) Configure the InitialContextFactory class to use java.naming.factory.initial = org.apache.qpid.jms.jndi.JmsInitialContextFactory Configure the ConnectionFactory connectionfactory.myFactoryLookup = amqp://localhost:5672 Configure the destination queue.myDestinationLookup = queue package org.jboss.amq.example; import jakarta.jms.Connection; import jakarta.jms.ConnectionFactory; import jakarta.jms.DeliveryMode; import jakarta.jms.Destination; import jakarta.jms.ExceptionListener; import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.MessageProducer; import jakarta.jms.Session; import jakarta.jms.TextMessage; import javax.naming.Context; import javax.naming.InitialContext; public class Sender { public static void main(String[] args) throws Exception { try { Context context = new InitialContext(); 1 ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup"); Destination destination = (Destination) context.lookup("myDestinationLookup"); 2 Connection connection = factory.createConnection("<username>", "<password>"); connection.setExceptionListener(new MyExceptionListener()); connection.start(); 3 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 4 MessageProducer messageProducer = session.createProducer(destination); 5 TextMessage message = session.createTextMessage("Message Text!"); 6 messageProducer.send(message, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); 7 connection.close(); 8 } catch (Exception exp) { System.out.println("Caught exception, exiting."); exp.printStackTrace(System.out); System.exit(1); } } private static class MyExceptionListener implements ExceptionListener { @Override public void onException(JMSException exception) { System.out.println("Connection ExceptionListener fired, exiting."); exception.printStackTrace(System.out); System.exit(1); } } } package org.jboss.amq.example; import jakarta.jms.Connection; import jakarta.jms.ConnectionFactory; import jakarta.jms.Destination; import jakarta.jms.ExceptionListener; import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.MessageConsumer; import jakarta.jms.Session; import jakarta.jms.TextMessage; import javax.naming.Context; import javax.naming.InitialContext; public class Receiver { public static void main(String[] args) throws Exception { try { Context context = new InitialContext(); 1 ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup"); Destination destination = (Destination) context.lookup("myDestinationLookup"); 2 Connection connection = factory.createConnection("<username>", "<password>"); connection.setExceptionListener(new MyExceptionListener()); connection.start(); 3 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 4 MessageConsumer messageConsumer = session.createConsumer(destination); 5 Message message = messageConsumer.receive(5000); 6 if (message == null) { 7 System.out.println("A message was not received within given time."); } else { System.out.println("Received message: " + ((TextMessage) message).getText()); } connection.close(); 8 } catch (Exception exp) { System.out.println("Caught exception, exiting."); exp.printStackTrace(System.out); System.exit(1); } } private static class MyExceptionListener implements ExceptionListener { @Override public void onException(JMSException exception) { System.out.println("Connection ExceptionListener fired, exiting."); exception.printStackTrace(System.out); System.exit(1); } } } <dependency> <groupId>io.netty</groupId> <artifactId>netty-tcnative</artifactId> <version>2.0.61.redhat-00001</version> <classifier>linux-x86_64-fedora</classifier> </dependency> amqp://myhost:5672?amqp.saslMechanisms=GSSAPI failover:(amqp://myhost:5672?amqp.saslMechanisms=GSSAPI) -Djava.security.auth.login.config=<login-config-file> amqp-jms-client { com.sun.security.auth.module.Krb5LoginModule required useTicketCache=true; }; connection.createSession(false, 101); connection.createSession(false, 100); <dependency> <groupId>io.jaegertracing</groupId> <artifactId>jaeger-client</artifactId> <version>USD{jaeger-version}</version> </dependency> amqps://example.net? jms.tracing=opentracing import io.jaegertracing.Configuration; import io.opentracing.Tracer; import io.opentracing.util.GlobalTracer; public class Example { public static void main(String[] args) { Tracer tracer = Configuration.fromEnv(" <service-name> ").getTracer(); GlobalTracer.registerIfAbsent(tracer); // } } export JAEGER_SAMPLER_TYPE=const export JAEGER_SAMPLER_PARAM=1 java -jar example.jar net.example.Example /home/ <username> /.m2/settings.xml C:\Users\<username>\.m2\settings.xml <settings> <profiles> <profile> <id>red-hat</id> <repositories> <repository> <id>red-hat-ga</id> <url>https://maven.repository.redhat.com/ga</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>red-hat-ga</id> <url>https://maven.repository.redhat.com/ga</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>red-hat</activeProfile> </activeProfiles> </settings> <project> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>example-app</artifactId> <version>1.0.0</version> <repositories> <repository> <id>red-hat-ga</id> <url>https://maven.repository.redhat.com/ga</url> </repository> </repositories> </project> <repository> <id>red-hat-local</id> <url>USD{repository-url}</url> </repository> <broker-instance-dir> /bin/artemis run example-broker/bin/artemis run __ __ ____ ____ _ /\ | \/ |/ __ \ | _ \ | | / \ | \ / | | | | | |_) |_ __ ___ | | _____ _ __ / /\ \ | |\/| | | | | | _ <| '__/ _ \| |/ / _ \ '__| / ____ \| | | | |__| | | |_) | | | (_) | < __/ | /_/ \_\_| |_|\___\_\ |____/|_| \___/|_|\_\___|_| Red Hat AMQ <version> 2020-06-03 12:12:11,807 INFO [org.apache.activemq.artemis.integration.bootstrap] AMQ101000: Starting ActiveMQ Artemis Server 2020-06-03 12:12:12,336 INFO [org.apache.activemq.artemis.core.server] AMQ221007: Server is now live <broker-instance-dir> /bin/artemis queue create --name queue --address queue --auto-create-address --anycast <broker-instance-dir> /bin/artemis stop