@@ -26,9 +26,10 @@ public static void main(String args[]) throws Exception {
2626 String hostname = getEnv ("RABBITMQ_HOSTNAME" , "localhost" );
2727 String port = getEnv ("RABBITMQ_AMQP_PORT" , "5672" );
2828 String scheme = getEnv ("RABBITMQ_AMQP_SCHEME" , "amqp" );
29+ String uri = scheme + "://" + hostname + ":" + port ;
2930 String username = args .length > 0 ? args [0 ] : getEnv ("RABBITMQ_AMQP_USERNAME" , "guest" );
3031 String password = args .length > 1 ? args [1 ] : getEnv ("RABBITMQ_AMQP_PASSWORD" , "guest" );
31- String uri = scheme + "://" + hostname + ":" + port ;
32+
3233 boolean usemtls = Boolean .parseBoolean (getEnv ("AMQP_USE_MTLS" , "false" ));
3334 String certsLocation = getEnv ("RABBITMQ_CERTS" );
3435
@@ -41,6 +42,7 @@ public static void main(String args[]) throws Exception {
4142 connectionParams .add ("transport.trustAll=true" );
4243
4344 if (usemtls ) {
45+ connectionParams .add ("amqp.saslMechanisms=EXTERNAL" );
4446 connectionParams .add ("transport.keyStoreLocation=" + certsLocation + "/client_rabbitmq.jks" );
4547 connectionParams .add ("transport.keyStorePassword=foobar" );
4648 connectionParams .add ("transport.keyAlias=client-rabbitmq-tls" );
@@ -64,7 +66,8 @@ public static void main(String args[]) throws Exception {
6466 ConnectionFactory factory = (ConnectionFactory ) context .lookup ("myFactoryLookup" );
6567 Destination queue = (Destination ) context .lookup ("myQueueLookup" );
6668
67- try (Connection connection = factory .createConnection (username , password )) {
69+ try (Connection connection =
70+ createConnection (factory , usemtls , username , password )) {
6871 connection .start ();
6972
7073 Session session = connection .createSession (false , Session .AUTO_ACKNOWLEDGE );
@@ -82,5 +85,12 @@ public static void main(String args[]) throws Exception {
8285
8386 assertEquals (message .getText (), receivedMessage .getText ());
8487 }
88+ }
89+ private static Connection createConnection (ConnectionFactory factory ,
90+ boolean usemtls , String username , String password ) throws jakarta .jms .JMSException {
91+ if (usemtls ) {
92+ return factory .createConnection ();
93+ }
94+ return factory .createConnection (username , password );
8595 }
8696}
0 commit comments