Aidan Skinner wrote:
On Wed, Feb 18, 2009 at 7:19 PM, Rafael Schloming <[email protected]> wrote:

Rajith Attapattu wrote:
Aidan,

I came across this when I wrote a simple test to figure out another issue.
Basically I did the following.

create connection
start the connection
create a session
create a destination, using that create a MC and a MP.
set a MessageListener to the MC.
send messages using MP.

When the session tries to deliever the messages it throws an
IllegalStateException as the dispatcher thread is null.

Let me create a JIRA and then attach the test case and the stack trace.
Strictly speaking I believe the JMS api-doc says that the behavior in the
above scenario is undefined. From the api-doc:

"The effect of calling MessageConsumer.setMessageListener  while messages
are being consumed by an existing listener or the consumer is being used to
consume messages synchronously is undefined."

I think this means that throwing an IllegalStateException is valid, however
that doesn't mean we can't do something a bit more graceful if we want to.

I think that should be OK, I don't see why using a the same session to
send and receive messages should be a problem. A patch with this as a
QpidTestCase would be worth having.

It's not the sending and receiving that's an issue. It's when exactly you start the connection. This is fully equivalent but would only depend on well defined JMS semantics:

create connection
create a session
create a destination, using that create a MC and a MP.
set a MessageListener to the MC.
start the connection
send messages using MP.

Note that starting the connection was simply moved after the message listener was set. This is the pattern recommended by the Connection api-doc, i.e. set up all your listeners and any other local app state first, and then start the connection. This avoids potential issues with race conditions where your listeners may start receiving messages before the app is fully ready to receive them.

--Rafael

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to