KBR
KBR

Reputation: 494

MDB bean pool vs Spring JMS concurrent consumers

I am from EJB background working on MDBs for asychronus message processing. Recently I am moved to a project where Spring messaging is used . Being new to Spring JMS listeners , I am kind of confused when it comes to comparing the concurrency semantics with MDBs.

MDB - As I understand , we dont need to worry about thread safety , it maintains a pool of MDB beans (Pool size is something we can configure) . Whenever a new message comes to destination (queue) . EJB Container picks an instance from the pool and process the message .

Spring - I am not sure if I understand it completely . We define a listener class inside a container . I don't know if it will process every in-coming message with a new instance of listener-class or it will create a new thread ( like we have in servlets ) ? Another thing I am confused with is configurable parameter concurrentConsumers , is it similar to what we have pool of beans in EJB container ?

Upvotes: 1

Views: 3316

Answers (1)

gpeche
gpeche

Reputation: 22514

Spring semantics are applied, so in the typical case your listener bean is a singleton and you have to guarantee thread safety yourself. Of course this is trivial: if you had this

public class MDB implements MessageListener {
    public void onMessage(Message inMessage) {
        ...blablabla...
    }
}

Now you could have basically:

public class SpringMessageListener implements MessageListener {
    public void onMessage(Message inMessage) {
        MDB mdb = new MDB(...parameters MDB might need...);
        mdb.onMessage(inMessage);
    }   
}

Upvotes: 1

Related Questions