Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

consumer question for NMS .Net app

$
0
0
details:

created c# .net 4 dll for excel using the excel RTD interface
nms and nms.activemq dlls v 1.6.0 and 1.6.1

I start my broker as:
ApacheMQ\apache-activemq-5.10.0-bin\apache-activemq-5.10.0\bin\win64

Ive taken the out of the box settings for everything.

I register interest in an RTD topic from excel as:

private ISession session;
private bool blnUpdateNotifyCalled = false;
private string sServiceAddress = "activemq:tcp://mypcname:61616";

public object ConnectData(int topicId, ref Array Strings, ref bool
GetNewValues)

string messageSubject = Strings.GetValue(0) as string;

String messageDestination = "topic://" + messageSubject;
_subscriptions.Add(topicId, messageDestination);
_destinations.Add(messageDestination, 0);
_topicId = topicId;

IDestination destination =
SessionUtil.GetDestination(session, messageDestination);
IMessageConsumer consumer =
session.CreateConsumer(destination);
consumer.Listener += new MessageListener(OnMessage);
GetNewValues = true;

//get the current value on bus
ITextMessage message = consumer.Receive() as ITextMessage;
return message.Text;..................

another one-time setup method creates the types at service startup:

Uri connecturi = new Uri(sServiceAddress);
IConnectionFactory factory = new
NMSConnectionFactory(connecturi);
IConnection connection = factory.CreateConnection();
session = connection.CreateSession();
connection.Start();

this is how i send a topic to the bus:

IDestination destination =
SessionUtil.GetDestination(session, "topic://" + topic + "~" + sField);
using ( IMessageProducer producer =
session.CreateProducer(destination) )

ITextMessage request =
session.CreateTextMessage(messageToPost);
request.NMSCorrelationID = Guid.NewGuid().ToString();
request.Properties["NMSXGroupID"] = "xyz";
request.Properties["myHeader"] = "xyzpubsub";
producer.Send(request);

=============================================

This all works perfectly well EXCEPT for when a topic with a value is
already on the bus and the ConnectData gets called and does not return any
value.
this is the error line : ITextMessage message = consumer.Receive() as
ITextMessage;
error =
"Apache.NMS.NMSException: Cannot set Async listeners on Consumers with a
prefetch limit of zero\r\n at
Apache.NMS.ActiveMQ.MessageConsumer.CheckMessageListener() in
c:\\dev\\NMS.ActiveMQ\\src\\main\\csharp\\MessageConsumer.cs:line 1569\r\n
at Apache.NMS.ActiveMQ.MessageConsumer.Receive() in
c:\\dev\\NMS.ActiveMQ\\src\\main\\csharp\\MessageConsumer.cs:line 336\r\n
at RTDServers.RTDDataServer.ConnectData(Int32 topicId, Array Strings,
Boolean GetNewValues) in C:\\PubSubAddin\\PubSubAddin\\Subscribe.cs:line
160"

But when i change the value of the topic and the listener fires - the result
is returned.

Question:
How can i get the ConnectData to have a consumer object have a listener and
also return the value on the bus if one currently exisits?

Viewing all articles
Browse latest Browse all 5648

Trending Articles