Reputation: 697
i use Azure Service Bus and want to send message to all subscribers in Topic. Client's app is written in JavaFX and for handling i use next code:
IMessageHandler messageHandler = new IMessageHandler() {
// callback invoked when the message handler loop has obtained a message
public CompletableFuture<Void> onMessageAsync(IMessage message) {
String body = new String(message.getBody());
System.out.println(body);
decorator.showToastWithTitleAndBody("", body);
return receiveClient.abandonAsync(message.getLockToken());
}
public void notifyException(Throwable throwable, ExceptionPhase exceptionPhase) {
System.out.printf(exceptionPhase + "-" + throwable.getMessage());
}
};
receiveClient.registerMessageHandler(
messageHandler,
// callback invoked when the message handler has an exception to report
// 1 concurrent call, messages are auto-completed, auto-renew duration
new MessageHandlerOptions(1, true, Duration.ofSeconds(1)));
In "onMessageAsync" method i use abandonAsync to not delete message and for the next recivers will get message. But i got lot's of message with the same content in each app instance. If i use completeAsync method message will remove and no one else will get it.
Is it real to send message to all subscribers in Topic without removing and withou duplicate?
Upvotes: 0
Views: 114
Reputation: 25994
Your message handler is configured to automatically complete the incoming messages. Yet, within callback method messages are abandoned. That means they'll never be auto-completed, and rather redelivered as many times as the MaxDeliveryCount
of the subscription is configured to (assuming you're fetching messages from the subscription).
The handler code should not abandon and either let auto-completion takes it's place or, alternatively, disable auto-completion and invoke .completeAsync()
once handler is done with the incoming message.
Also, auto-renew is defined as 1 second. That's off. This should be at least longer than LockDuration
period or not specified at all.
Is it real to send message to all subscribers in Topic without removing and withou duplicate?
Yes. You won't need de-duplication as it's not an issue of duplicates being sent, but duplicate processing.
Upvotes: 1