I am implementing a subscription-based reading of messages from IBM MQ websphere and I am using IBM.XMS.dll
which has an event-based mechanization. Following is my code for subscription:
T
is the type of data accepted by the callback function onMessageReceived
. I will have to parse the message body from IMessage
, convert to type T and invoke onMessageReceived
fromOnMQMessageCallback
public override void Subscribe<T>(Action<T> onMessageReceived)
{
try
{
MessageListener messageListener = new MessageListener(OnMQMessageCallback);
_consumer.MessageListener = messageListener;
_connection.Start();
}
catch (Exception ex)
{
throw;
}
}
private void OnMQMessageCallback(IMessage msg)
{
try
{
//I want to invoke onMessageReceived in this method
}
catch (Exception)
{
throw;
}
}
From OnMQMessageCallback
, I want to invoke onMessageReceived()
which is passed into the Subscribe()
method from the caller. I cannot figure out how to do it.