Skip to content

Commit

Permalink
Fix standalone brokerUri name vs address usage
Browse files Browse the repository at this point in the history
  • Loading branch information
michalxo committed Jan 31, 2025
1 parent 65fd6be commit 6f88745
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,33 @@ public static void ensureSameMessages(int totalProducedMessages, Map<String, Mes
}
}

protected String getAmqpBrokerUri(ArtemisContainer artemis, DeployableClient deployableClient) {
String brokerUriName = Constants.AMQP_URL_PREFIX + artemis.getName() + ":" + DEFAULT_AMQP_PORT;
String brokerUriAddress = Constants.AMQP_URL_PREFIX + artemis.getContainerIpAddress() + ":" + DEFAULT_AMQP_PORT;
try {
LOGGER.info("Trying to use artemis container name in brokerURI.");
testSimpleSendReceive(deployableClient, brokerUriName, "testConnectionQueue", ArtemisConstants.ADMIN_NAME, ArtemisConstants.ADMIN_PASS);
return brokerUriName;
} catch (Exception e) {
LOGGER.warn("Failed. Using IP address in brokerURI instead.");
return brokerUriAddress;
}
}

// ==== Messaging methods
protected void testSimpleSendReceive(DeployableClient deployableClient, String brokerUri, String queue, String username, String password) {
Map<String, String> clientOptions = Map.of(
"conn-username", username,
"conn-password", password,
"address", "testMeAddress",
"count", "1"
);
MessagingClient messagingClient = new AmqpQpidClient(deployableClient, brokerUri, clientOptions, clientOptions);
messagingClient.sendMessages();
messagingClient.receiveMessages();
deleteQueue(deployableClient, queue);
deleteAddress(deployableClient, queue);
}
protected void deleteAddress(DeployableClient artemisDeployableClient, String name) {
BundledArtemisClient artemisClient = new BundledArtemisClient(artemisDeployableClient, ArtemisCommand.ADDRESS_DELETE, Map.of("name", name));
artemisClient.executeCommand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ void setupEnv() {
LOGGER.info("Creating artemis instance: " + artemisName);
artemis = ArtemisDeployment.createArtemis(artemisName);
// BrokerService.getAmqpPort?
brokerUri = Constants.AMQP_URL_PREFIX + artemis.getName() + ":" + DEFAULT_AMQP_PORT;
stDeployableClient = new StJavaClientDeployment();
artemisDeployableClient = new BundledClientDeployment();
brokerUri = getAmqpBrokerUri(artemis, artemisDeployableClient);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void setupEnv() {
LOGGER.info("Creating artemis instance: " + artemisName);
artemis = ArtemisDeployment.createArtemis(artemisName);
deployableClient = new StJavaClientDeployment();
brokerUri = Constants.AMQP_URL_PREFIX + artemis.getName() + ":" + DEFAULT_AMQP_PORT;
brokerUri = getAmqpBrokerUri(artemis, deployableClient);
}

private void doTestTransactions(String address, Map<String, String> senderOptions, Map<String, String> receiverOptions, int receiverExpMsgCount, int leftoverMessages) {
Expand Down

0 comments on commit 6f88745

Please sign in to comment.