I'm writting a Java application for messaging between two or more clients. I'm using JMS (Java Messaging Service). For receiving message I wrote a MessageListener object that implements the javax.jms.MessageListener with onMessage method.
I'm wondering if the MessageListener object is some kind of background thread? I think it is a thread, because MessageListener receives and processes messages while my application is working on other things.
Every JMS provider implements their own JMS client so it's impossible to answer this question with 100% certainty without knowing what JMS client you're using, but in general the onMessage method of a javax.jms.MessageListener will be invoked in another thread in order to receive messages asynchronously as defined in the JMS specification.
Related
I am working on a POC using Spring Integration and STOMP. The initial POC is successful.
I followed the adapters configuration mentioned in https://docs.spring.io/spring-integration/reference/html/stomp.html#stomp
In my POC, I did not include the last two #Bean definitions from the above link.
Inbound Channel Adapter and Message Handlers were sufficient to handle the incoming messages.
Now, my question is:
What is the difference between Inbound channel adapters and application event listing message producers?
Is ApplicationListener used when we follow DSL as mentioned in an example here?
Thanks,
Mahesh
Well, as you noticed in that Spring Integration documentation about STOMP support there is some bunch of ApplicationEvents emitted by STOMP Channel Adapters. You indeed can handle them using regular ApplicationListener (#EventListener) if your logic for handling those events is pretty much simple and doesn't need further distribution. But if your logic is much complicated and you may need store an even (or its part) in some database, or send via email, do that in parallel after some aggregtion, etc., then indeed that ApplicationEventListeningMessageProducer is much better solution when we have Spring Integration on board already.
However if you talk about a StompInboundChannelAdapter nature and relationship with those mentioned events, you need to take a look into the StompIntegrationEvent implementations. You quickly realize that there is no events for payload in the STOMP frame. So, that is what is done really by the StompInboundChannelAdapter - it produces messages based on the body from STOMP frame.
All the mentioned events emitted fro that channel adapter are more about that adapter state sharing for possible management in your application.
I am using the Whole Message Delivery functionality of Jetty Websockets.
In such a case, Joakime says that Websocket messages are guaranteed to be delivered in order.
I am going to go on a limb and assume that all Websocket event-handling methods will be invoked by the same thread.
Now, say an external timer expires and I need to send a message over the websocket. The timer runs in one thread and the Websocket events run on a different thread.
Do I need to make my Websocket event handlers thread-safe (seeing as their state will be accessed by the timer and Websocket thread)? Or is there a way for the timer thread to pass a task to the Websocket thread to execute?
The Jetty WebSocket API (Native or javax.websocket) doesn't care about the thread safeness of the local WebSocket End Point.
It will deliver the next message when it arrives.
Note: you can control suspend / resume of the read thread with the Jetty Native WebSocket API.
I have a method that is called as a callback from some communication library when data are received.
Using Spring Integration, I would like to send data to a specific Channel that will be later picked up by some Sender and some Database Recorder. These two may work in parallel. How could I do it?
I prefer not to use XML for anything.
These two may work in parallel.
For this purpose Spring Integration provides PublishSubscribeChannel. With its executor option you really can make subscribers working in parallel.
I would like to send data to a specific Channel
So, just do that from that callback method.
You can consider to use Messaging Gateway for dependency injection instead of direct channel injection for sending.
That way you will call the gateway's method from that callback and the data will be send to predefined PublishSubscribeChannel channel for distribution between its subscribers.
how do I create that "existing channel"
That's all about Spring and its inversion of control implementation.
You may consider to consult existing Spring Integration Samples for ideas.
Is there any way to get the entire SOAP message inside channel interceptor call back methods ? Is there any MessageContext injected by default to any of the callback methods?
The question doesn't sound good. The ChannelInterceptor does not do anything with SOAP. They know only about the channels and messages to pass.
In general Spring Integration is stateless, so no any context injected to the channel interceptor.
Any MessageContext is responsibility of your own application.
One of the approach is a MessageHeaders as I recommend you in your other questions: before sending message to the channel you store something to its headers and than you have access to that object from the channel interceptor methods via provided message.
I am starting to use D-Bus as the IPC mechanism for a new project in Linux/KDE. And I've discovered that the documentation does not really address concurrency at all. How are D-Bus services expected to deal with multiple concurrent calls coming in from different clients? What's the threading model? Can a service assume that it is single-threaded and D-Bus will queue up requests on its own?
As a protocol, D-Bus doesn't address threading.
D-Bus connections receive message serially. At the protocol level, replies to message are asynchronous: i.e. the sender doesn't have to wait for replies before sending more messages.
While in principle a D-Bus implementation could dispatch messages to service implementations concurrently, I don't know of any that do this.
Typically, a D-Bus implementation (or "binding", if you will) allows the service to decide for each method (or even for each method call) whether to respond to incoming method calls synchronously or asynchronously. The details of this are up to the particular implementation you're using.
If you're responding to method calls asynchronously, your service implementation is responsible for making sure that any state is kept consistent while multiple responses are pending. If you always respond synchronously, then you know you're only dealing with one method call at a time.