Topic
  • 3 replies
  • Latest Post - ‏2012-12-11T09:57:30Z by Shashikanth@BLR
SystemAdmin
SystemAdmin
8523 Posts

Pinned topic MQ Pub/Sub in .NET - how to get notified of a new message in application

‏2012-12-07T16:12:56Z |
Hello,

I am new in MQ Pub/Sub and not sure how subscriber in an application gets notified if a message is published to topic.
At the moment I have used IBM sample code.

What is in place right now:
WCF Client publishes a message using Put(...) method of MQQueueManager.
Then WCF Client then informs the WCF Service ( which acts as Subscriber) that message is published on Topic using contract method.
Only then WCF Service goes and checks whether message is there and gets it.

So it acts as follows:
Client -> Topic
Client -> Service then Service -> Topic
What I actually need:
Once WCF Client publishes message on topic, I want the WCF Service to know that something is published on Topic without interaction with WCf Client.
So it acts as follows:
Client -> Topic-> Service
Is there any way to do it?
I have spent so much time on WebSphere examples and could not find it.

Any help appreciated.
Regards,
Assel
Updated on 2012-12-11T09:57:30Z at 2012-12-11T09:57:30Z by Shashikanth@BLR
  • Shashikanth@BLR
    Shashikanth@BLR
    132 Posts

    Re: MQ Pub/Sub in .NET - how to get notified of a new message in application

    ‏2012-12-07T17:57:33Z  
    Are you using MQ WCF custom channel develop the web service? meaning are you hosting your web service on MQ? MQ WCF custom channel currently supports invoking of web services only using queues but not topic.

    If you are not using MQ WCF custom channel, then to subscribe you need to use the AccessTopic method of MQQueueManager class to create subscription. Once the subscription is created, then you need to do call the Get method to receive messages. The sample code below demonstrates the receiving of publication. You can put the Get call in a loop to continuously receive messages. You can also add wait time in Get call to for a short period of time. If no publications are received in the given wait time, the call will return with no messages.

    There is no need for WCF client to tell the service to go and receive publication.

    MQQueueManager queueManager = new MQQueueManager(queueManagerName, properties);
    MQTopic topic = queueManager.AccessTopic(topicName, null, MQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, MQC.MQSO_CREATE | MQC.MQSO_FAIL_IF_QUIESCING);
    topic.Get(message);

    HTH
  • SystemAdmin
    SystemAdmin
    8523 Posts

    Re: MQ Pub/Sub in .NET - how to get notified of a new message in application

    ‏2012-12-11T09:46:11Z  
    Are you using MQ WCF custom channel develop the web service? meaning are you hosting your web service on MQ? MQ WCF custom channel currently supports invoking of web services only using queues but not topic.

    If you are not using MQ WCF custom channel, then to subscribe you need to use the AccessTopic method of MQQueueManager class to create subscription. Once the subscription is created, then you need to do call the Get method to receive messages. The sample code below demonstrates the receiving of publication. You can put the Get call in a loop to continuously receive messages. You can also add wait time in Get call to for a short period of time. If no publications are received in the given wait time, the call will return with no messages.

    There is no need for WCF client to tell the service to go and receive publication.

    MQQueueManager queueManager = new MQQueueManager(queueManagerName, properties);
    MQTopic topic = queueManager.AccessTopic(topicName, null, MQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, MQC.MQSO_CREATE | MQC.MQSO_FAIL_IF_QUIESCING);
    topic.Get(message);

    HTH
    Thanks for reply, but I knew about this solution already.
    I wanted to avoid waiting in a loop process.
    Do not want to force subscriber to get message, want it to know when message is published.
    No worries anyways, I am just doing research of possible solutions in different platforms.
  • Shashikanth@BLR
    Shashikanth@BLR
    132 Posts

    Re: MQ Pub/Sub in .NET - how to get notified of a new message in application

    ‏2012-12-11T09:57:30Z  
    Thanks for reply, but I knew about this solution already.
    I wanted to avoid waiting in a loop process.
    Do not want to force subscriber to get message, want it to know when message is published.
    No worries anyways, I am just doing research of possible solutions in different platforms.
    Well, if you are doing research, then you can consider IBM Message Service Clients (XMS .NET) that provides a Message Listener which gets automatically invoked when a message arrives on a queue or topic. From the programming point of view XMS .NET is quite similar to JMS. So you can reuse any of JMS skills. XMS also gets shipped with MQ Clients. So if you have MQ v701 and above, you will have XMS also installed.

    Happy researching :)