Comments (12)
Your observation is right. What are you doing in the onMessageAsync() implementation? Are you calling a blocking operation in it like Thread.sleep()? Java ForkJoinPool.commonPool starts with threads equal to the number of CPU cores. It is supposed to create more threads based on demand, but it can't handle blocking operations. onMesssageAsync() is supposed to be an async operation, not to block. If you are blocking, use a smaller number for max concurrent sessions.
from azure-service-bus-java.
Hi,
Not doing anything blocking in onMessageAsync
Is it correct implementation of it?
@Override
public CompletableFuture<Void> onMessageAsync(IMessageSession session, IMessage message) {
System.out.println("SessionID: " + session.getSessionId() + " - Message Received - " + message.getMessageId() + " - " + new Date().toString());
try {
completeMessage(session, message);
}
catch (Exception ex) {
throw new RuntimeException(ex);
}
return CompletableFuture.completedFuture(null);
}
========================================
Thanks,
Edouard
from azure-service-bus-java.
completeMessage() is most likely blocking, I am assuming you call session.complete(message.getLockToken()). complete() call is internally session.completeAsync().get().. which is a blocking call.
If all you want to do is complete in the onMessageAsync.. there is a better option. SEt AutoComplete=true in session handler options. Or return session.completeAsync() in onMessageAsync.
from azure-service-bus-java.
We do not want to set Autocomplete to true,
Because there will be complex message proceeding (validation/transformation/sending to another queue)instead of completeMessage() there and regardless of status the message will be complete, or not complete, or sent to DeadLetterQueue.
Is there another way to process message rather than in onMessageAsync?
We need to get a message, process it, and complete, or not etc.
from azure-service-bus-java.
Ok.
Ideally you should perform such tasks like validation,transformation in asynchronous way.
Or just increase the parallelism level of ForkJoinPool.commonPool, using the system property "java.util.concurrent.ForkJoinPool.common.parallelism" as mentioned in [https://docs.oracle.com/javase/8/docs/api/index.html?java/util/concurrent/ForkJoinPool.html] . Set the system property to something more than max concurrent sessions... so there are always some non blocked threads.
from azure-service-bus-java.
Thank you for the System Property tip!
Would you please answer two more questions because we just starting use of ServiceBus
- You said: Ideally you should perform such tasks like validation,transformation in asynchronous way.
Is this ok method to achieve our task like below,
or there is some other way access messages outside of onMessageAssync,
please just provide a skeleton of such thing.
======================
@OverRide
public CompletableFuture onMessageAsync(IMessageSession session, IMessage message) {
processMessage(session, message);
return CompletableFuture.completedFuture(null);
}
====================== - Is there a way to stop the SessionHandler from receiving any more messages without removing it?
Thanks,
Edouard
from azure-service-bus-java.
- your code works. But it is not async. Async works if other methods that you call are also async, like if you have a processMessageAsync instead of processMessage. A workaround is to wrap your synchronous code in a Callable and submit it to a thread pool. Create a new completablefuture and complete it inside the call method of the callable, when the actual processing completes. That way you can submit your callable to the thread pool and return the completablefuture right after that. It is ok even if you don't do it the aysnc way. Just increase the thread count using the system property. You should be fine.
To the second part of your question, we will soon make public Sender and Receiver implementations. With a Receiver, you can call receive() to receive just one message. We will push it sometime next week. - No.. There is no way to stop the SessionHandler from receiving any more messages. Just close the queue client when you want to stop receiving.
from azure-service-bus-java.
New Receiver sounds very promising, we may have more control on the flow, thank you.
What are new Sender features comparing to the existing sender - queueClient.send(message); ?
Does new Receiver support Sessions in queues/topic's subscriptions, does it also have onMessage/onSession options?
What about performance comparison of the new Receiver vs Session Handler?
from azure-service-bus-java.
Sender features are same as QueueClient.
Yes.. you can get a session receiver object..
Performance will be same as QueueClient internally uses senders and receivers.
from azure-service-bus-java.
- Sender features are same as QueueClient.
What is new then in new Sender version?
Does new Receiver also have onMessage/onSession options?
from azure-service-bus-java.
@eperov - No. While the below issue is for the .NET client, it will give a brief description of what we are envisioning with the client vs. sender/receiver functionality.
Azure/azure-service-bus-dotnet#87
The bottom line though, is that clients are the "easy getting started scenario" that will cover most use cases, while sender/receivers provide advanced functionality, and some additional knobs to customize your experience.
from azure-service-bus-java.
Closing, please comment back here to reopen if needed.
from azure-service-bus-java.
Related Issues (20)
- MessageAndSessionPump closes the connection on the receipt of SIGTERM.
- Memory Leak
- receiveMessages method with maxWaitTime not working as expected
- @ServiceBusQueueTrigger MSI authentication
- Azure service bus jar changing default Spring Boot behavior HOT 9
- ServiceBusSenderClient sendMessage method doesn't return MessageId after pushing the message to the queue/topic HOT 1
- Getting "ReactorDispatcher instance is closed" error when trying to close the azure service bus connection after receiving message HOT 14
- How to setup Message Listener to pickup message immediately on arrival (Pricing Tier: Basic)
- Azure event hub connection is closed error HOT 1
- Error occurred while refreshing token that is not retriable. Not scheduling refresh task.
- Infinite Receiver/Subscriber Issue | Java 11 | Spring Boot 2.5.* HOT 2
- Error processing ASB queues with Spring Boot and Apache Camel
- Transaction acknowledgement issue
- This repo is missing important files
- How can I get message attributes in Azure func
- LockRenewalOperation exception when marking message as abandon/complete on same client HOT 1
- Inconsistent Behavior of getLockedUntil() Method for Messages Received from Azure Service Bus Queue
- Consumer Fails to Reconnect and Consume Messages with Apache Qpid JMS Client (Version 0.51.0)
- Service Bus Client Mock Bean creation
- Security vulnerability in version 7.14.3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-service-bus-java.