This discussion is archived
6 Replies Latest reply: Dec 6, 2012 5:54 PM by Jeets RSS

Issue with onMessage Event Handler

975028 Newbie
Currently Being Moderated
Hi,

I am using the sample code provided on the Oracle Site to connect my .Net layer with JMS Topic.

When i establish a connection, and use the following code

ITextMessage recvMessage = (ITextMessage)consumer.Receive(500);

i am able to consume the messages just fine from the Topic.

But when i implement the onMessage Event handler using this code:

ISession consumerSession = connection.CreateSession(
Constants.SessionMode.AUTO_ACKNOWLEDGE);

IMessageConsumer consumer = consumerSession.CreateConsumer(topic);

consumer.Message += new MessageEventHandler(this.OnMessage);

public void OnMessage(IMessageConsumer consumer, MessageEventArgs args)
+{+

PrintMessage("Received Message Asynchronously:", args.Message);
+}+

The onMessage function is not being invoked. I know there are messages in the Topic, but still for some reason this method isnt being invoked.

Any clues on why this might be happening please ?

Thanks
Angad

Edited by: Angad Puri on Dec 4, 2012 3:28 PM
  • 1. Re: Issue with onMessage Event Handler
    Jeets Journeyer
    Currently Being Moderated
    Angad,

    The default implementation of onMessage() is as below:

    public void      onMessage(Message message)

    Guess you are overloading onMessage(), in this case you might have to manually call onMessage() method. It will not be invoked by container.

    Please let me know, if its correct.

    Thanks,
    Jeets
  • 2. Re: Issue with onMessage Event Handler
    Tom B Expert
    Currently Being Moderated
    Hi,

    There are two common possibilities:

    1: Messages won't be delivered to a receiver until you call "start()" on the connection you used to create the receiver's session.

    2: Topic subscriptions will not receive any messages that are sent before the subscription was created.

    There's sample onMessage code in the edocs:

    http://docs.oracle.com/cd/E21764_01/web.1111/e13746/app_examples.htm#i1059467

    HTH,

    Tom
  • 3. Re: Issue with onMessage Event Handler
    975028 Newbie
    Currently Being Moderated
    Hi Tom,

    Thanks for your response. I am using the exact sample code that you have shared.
    It has the start method to instantiate the connection.

    About the second point you mention.. I am not sure how to implement the wait functionality in .Net. I was hoping to implement a polling mechanism, i.e. a service continually hitting the Topic to check for messages.
  • 4. Re: Issue with onMessage Event Handler
    975028 Newbie
    Currently Being Moderated
    Hi Jeets,

    Was trying to work on the sample code provided by Oracle. So was wondering what is going wrong.

    Regards
    Angad
  • 5. Re: Issue with onMessage Event Handler
    Tom B Expert
    Currently Being Moderated
    This is the first time I've ever heard of the sample silently failing, and the sample has been in place for 5 years now. It's odd that you can get a synchronous topic consumer to work, but not an asynchronous consumer.

    I only have a few ideas what might be going wrong. Perhaps your environment is somehow very very slow, so the sample gives up and finishes before the message can arrive - try increasing the Sleep time to 10000 millis from 1000 in the sample. Perhaps there's some sort of uncaught exception being pushed to the client: modify the test code to have an "OnException" listener, register this listener with the connection, and have the listener print any exceptions that it gets. Perhaps there's some sort of problem on the server: check your server logs.

    Is there anything different about your environment? Which version of .NET are you using? What's the tuning of your Topic? (Did you turn it into a distributed topic?) Of WebLogic?
    I am not sure how to implement the wait functionality in .Net. I was hoping to implement a polling mechanism, i.e. a service continually hitting the Topic to check for messages.
    I haven't worked with .NET in a while, so I don't recall it's thread handling verbs. There should be no need for polling once you get the asynchronous consumer to work.

    Tom
  • 6. Re: Issue with onMessage Event Handler
    Jeets Journeyer
    Currently Being Moderated
    Hello Angad,

    In first place, for sure we can not help on .Net stuff, coming to the MDB part.

    Could you please let us know, what exactly you did from starting, with the samples provided by Tom.

    Am concerned that, it could be understanding issue too. So if you can provide us the detailed process you followed to work with the the files, probably we can get a clue on where the things going wrong/ if everything is in place. Don't hesitate to put even compiling the classes and creating JMS resources.

    Cheers,
    Jeets.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points