-
I'm trying to build a small bank app using the I'm trying to bind a queue to an exchange with a routing-key "account.create" but im RabbitMQ it always gets bound with the default routing-key "#". My YAML config is as follows: mp:
messaging:
outgoing:
bank-notifications:
connector: smallrye-rabbitmq
exchange:
name: bank-notifications
type: fanout
routing-key: ""
bank-responses:
connector: smallrye-rabbitmq
exchange:
name: bank-commands
type: direct
# default-routing-key: "response"
incoming:
account-create:
connector: smallrye-rabbitmq
queue:
name: account-create-queue
routing-keys: [account.create]
exchange:
name: bank-commands
type: direct The server side resource which creates the binding looks as follows: @ApplicationScoped
public class BankMessageResource {
private static final Logger LOG = Logger.getLogger(bank.rest.resources.AccountResource.class);
@Inject
BankSingleton bank;
@Inject
@Channel("bank-responses")
Emitter<MessageDTO> responseEmitter;
private final ObjectMapper objectMapper = JsonMapper.builder()
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true)
.build();
@Outgoing("bank-notifications")
public Publisher<String> accountNotifications() {
LOG.info("Subscribed to bank notifications");
return bank.getBank().getPublisher();
}
@Incoming("account-create")
public CompletionStage<Void> createAccount(Message<MessageDTO> message) {
message.ack();
LOG.info("Received account create message");
try {
var number = bank.getBank().createAccount(((AccountDTO) message.getPayload().getData()).getOwner());
Account account = bank.getBank().getAccount(number);
var responseData = /* create response data*/
sendResponse(responseData, getReplyTo(message));
} /* error handling */
return null;
}
private void sendResponse(MessageDTO response, String routingKey) {
LOG.info("Sending response with correlation ID: " + response.getCorrelationId() + " to " + routingKey);
OutgoingRabbitMQMetadata metadata = OutgoingRabbitMQMetadata.builder()
.withRoutingKey(routingKey)
.build();
responseEmitter.send(Message.of(response, Metadata.of(metadata))
.withAck(() -> {
LOG.info("Acknowledged response with correlation ID: " + response.getCorrelationId() + " to " + routingKey);
return CompletableFuture.completedFuture(null);
})
.withNack(throwable -> {
LOG.info("Failed to deliver message with correlation ID: " + response.getCorrelationId() + " to " + routingKey + ": " + throwable.getMessage());
return CompletableFuture.completedFuture(null);
}));
}
private <T> String getReplyTo(Message<T> message) {
return message.getMetadata(IncomingAmqpMetadata.class)
.map(IncomingAmqpMetadata::getReplyTo)
.orElse(null);
}
} The important thing being the YAML config which creates the bindings. In the exchange in RabbitMQ this is displayed: While the queue I've tried: routing-keys: account.create and routing-keys: "account.create" and routing-keys:
- account.create and routing-keys:
- "account.create" Can anyone tell me why the binding is not being created with the correct routing-key or am I running into a bug? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Nevermind, the key mp:
messages:
incoming:
account-create:
routing-keys: "account.create" |
Beta Was this translation helpful? Give feedback.
Nevermind, the key
routing-keys
is supposed to be on the level ofaccount-create
and not inqueue
. So the full path inapplication.yaml
should be: