Is there a way to tell if a Publisher is actually connected to the Neuron server?
Currently, we just try to send a test message to a test topic and check for exceptions. However, this might not be that efficient and we are hoping to find a better/faster way.
We know that we can attach to the OnOffline and OnOnline events but they are called for each topic and we are not sure if we can use this to test the actual server connection.
Please advise,
Thanks,
Dan
Tags: connection
Hi Dan,
if you are just testing, you can always use our test client. Just open it, select the publisher object and hit connect. you'll see the online events fire and each topic that it connects to will show up as green in the UI.
when connecting to a topic with a party, its actually a 2 step process. First the party needs to connect to the bus (i.e. management/boostrap service) to get its latest configuration information. If that's successful, it then needs to connect to each of its topics. hence, you'll find that the online/offline events fire for each topic that the Party has a subscription to.
if you are just using our API in code, the fundamentals tutorial has a good sample to show how to connect, catch and inspect errors and use the online and offline events:
http://support.neuronesb.com/downloads/NeuronFundamentals.zip
sample code would look something like this:
// Create an instance of a publisher
using (Publisher publisher = new Publisher(PUBLISHER))
{
publisher.OnOnline += new Channels.TopicEventHandler(publisher_OnOnline);
// catch any exceptions that may occurr while connecting to each individual topic
PartyConnectExceptions exceptions = publisher.Connect();
if (exceptions != null && exceptions.Count > 0)
{
foreach (var e in exceptions.GetResults())
Console.WriteLine(string.Format("An error occurred connecting '{0}' to Topic, '{1}'. {2}", publisher.Context.PartyId, e.Exception.Message, e.Topic));
}
else
{
// Send some XML. Body type is automatically set. Lots of different Send methods
publisher.SendXml(TOPIC, "<Test>dsfdsf</Test>");
}
}
Hi Marty,
Thanks for the quick rely and the sample source code. However, I find that if neuron is down that the Connect method throws an exception so does not return. Actually, this is fine for my purposes because I can just catch the exception so my code looks like this:
public bool IsConnectionUp(string serviceAddress, string zone, string partyId)
{
var subscriberConfiguration = new SubscriberConfiguration
{
ServiceAddress = serviceAddress,
ServiceIdentity = "",
SubscriberId = partyId,
Zone = zone
};
try
{
using (var publisher = new Publisher(subscriberConfiguration))
{
var exceptions = publisher.Connect();
if (exceptions != null && exceptions.Count > 0)
return false;
return true;
}
}
catch(Exception)
{
return false;
}
}
Does this look like it should cover most connectivity failures?
Neuron ESB Product Support Forums and Communities
© 2024 Created by Neuron Admin. Powered by