Getting TimeoutException on sending Informs via SharpSNMPLib - c#

I am using SharpSNMPLib on C# to send Informs but always getting a timeoutException. This is apparently caused by the lack of reply as stated on the documentation here :
Messenger.SendInform(0,
VersionCode.V2,
new IPEndPoint(IPAddress.Parse("192.168.1.3"), 162),
new OctetString("public"),
new ObjectIdentifier("1.3.6.1.2.1.1"),
0,
new List<Variable>(),
2000,
null,
null);
The manager should send back a reply to this INFORM message.
Otherwise, a TimeoutException occurs.
Does anyone know how to send back a reply in order to avoid this exception?

Answered offline, but paste the answer here for future reference.
The code base contains an snmptrapd sample, which illustrated how to construct a manager pipeline,
https://github.com/lextm/sharpsnmplib/blob/master/Samples/CSharp/snmptrapd/Program.cs
It is such a pipeline that handles incoming TRAP and INFORM messages and replies in a proper way.
You might further read the checkout steps to see how the test agent and snmptrapd should work together,
http://docs.sharpsnmp.com/en/latest/samples/command-line-tools.html#checkout
When an INFORM message is sent from the test agent after the button is clicked, the snmptrapd program will reply to it and log to console.

Related

NServiceBus sending message to one endpoint and waiting for reply in another

I'm using NServiceBus with RabbitMQ in my project. I have two services that don't know about each other and don't share anything. service1 publishes request messages to endpoint1 (queue1) and service2 listens to endpoint1 and publishes responses to endpoint2 (queue2). There are two questions:
How can service1 handle responses from service2 if service1 doesn't know the response message type but only expects some particular fields in the response message?
I want to create an async API method that sends a request to endpoint1 and waits for the response in endpoint2. Is it somehow possible at all? Also how can I ensure that the reply corresponds with the request?
I expect something like:
public async Task<object> SendRequest(string str) {
var request = new MyRequest(str);
await endPoint1.Publish(request);
var reply = await endPoint2.WaitingReply();
return reply;
}
I will appreciate any help.
Whenever two things communicate, there is always a contract. When functions call each other the contract is the parameters that are required to call that function. With messaging the message is the contract. The coupling is towards the message, not the sender or receiver.
I'm not really sure what you're trying to achieve? You mention an API which is async and endpoint1 and endpoint2.
First of all, there's asynchronous execution and asynchronous communication. The async part in your example code is asynchronous execution of two methods that have the word await in front of them. When we talk about sending messages, that's asynchronous communication. A message is put on the queue and then the code moves on and never looks back at the message. Even when you use the request/reply pattern, no code is actually waiting for a message.
You can wait for a message by blocking the thread, but I highly recommend you avoid that and not use the NServiceBus callback feature. If you think you have to, think again. If you still think so, read the red remarks on that page. If they can't convince you, contact Particular Software to have them explain another time why not. ;-)
It could be that you need a reply message for whatever reason. If you build some website using SignalR (for example) and you want to inform the user on the website when a message returned and some work was completed, you can wait for a reply message. The result is that the website itself becomes an endpoint.
So if the website is EndpointA and it sends a message to EndpointB, it is possible to reply to that message. EndpointA would then also need a message handler for that message. If EndpointB first needs to send a message to EndpointC, which in turn responds to EndpointB and only then it replies back to EndpointA, NServiceBus can't easily help. Not because it's impossible, but because you probably need another solution. EndpointA should probably not be waiting for that many endpoints to reply, so many things could go "wrong" and take too much time.
If you're interested to see how replies work in combination with SignalR and what not, you can check a demo I built for a presentation that has that.

Artalk XMPP library questions

I used Artalk XMPP nuget package in my C# application. I was able to send messages from the user account userA#domain.com to the user account userB#domain.com through Ignite OpenFire server on our LAN. There were several minor issues with the messages that are not showstoppers:
If I tried to provide a subject, it was prefixed with the word "Subject: " in the client. This is not a problem but I am wondering if this is a remote client or server thing.
The message body was wrapped in square brackets as [test message body]. This is not a big problem but I would rather avoid it, to preserve the message being sent as-is, for the possible automatic processing. Is this a remote client or server thing?
If message body contained XML, then it was sent successfully but never received. Is sending XML not allowed by XMPP protocol? Or is it a server or remote client thing?
Edit:
Since I asked the above bullet, I tried to use System.Security.SecurityElement.Escape() on the message body and wrapped it in <![CDATA[]]> and it was delievered with its XML preserved. The question still stands.
All successfully delivered messages have been also copied by userB back to userA. This is all right if userA is not interactive, but if it is also a real human being, then it may be annoying. Is this a server or remote client thing, and is there any way to avoid it? I know that the remote user's client does not do it with regular chat messages sent through a Jabber client to them.
Next, I had userB#domain.com invite userA#domain.com to a chat room conference.domain.com#conference.domain.com and tried to send messages to that chat room, still from userA#domain.com. No messages have been received in the conference room, and there was no exception thrown during the sending.
ArtalkXmppClient xmpp;
xmpp = new ArtalkXmppClient("domain.com", "userA#domain.com", "secret", 5222, true);
try
{
var msg = new Message(
"conference.domain.com#conference.domain.com",
"test message body",
"conference subject", // conference allows participants to change subject
null,
MessageType.Groupchat,
CultureInfo.CurrentCulture);
if (!xmpp.Connected)
{
xmpp.Connect("myapp");
}
xmpp.SendMessage(msg);
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
The solution to the group chat part of the question was to pre-create the group on the server before trying to send to it and to use MessageType.Chat.
The last part was counter-intuitive and I would have never figured it out, if I did not forget to enable group chat in the configuration during testing. When using MessageType.GroupChat or any type other than Chat it simply did not work.
Also, subject must be null, otherwise subject will change but no messages will be delivered. Changes of subject have to be sent on their own, separate messages without bodies.
The only side effect that I am noticing is that with group chat, as opposed to person-to-person chat, the messages appear escaped. I am not sure what escapes them as opposed to person-to-person chat, but this is kind of acceptable.

ActiveMQ access to previously published data on subscription

We're using ActiveMQ locally to transfer data between 5 processes that turn simultaneously.
I have some data I need to send to a process, both at runtime (which works perfectly fine), but also a default value on start. Thing is it is published when the process starts, it just doesn't read because it wasn't subscribed to the topic at the time the data was sent.
I have multiple solutions : I could delay the first publishing for a moment so that the process has time to launch (which doesn't seem very appealing) ; or is there a way to send all stored previously non-treated messages to some process that just subscribed ?
I'm coding in C#.
I don't have any experience with ActiveMQ, but other message system usually have an option which marks the subscription as persistent, which means that; after the first subscription; the message queue itself checks if a certain message is delivered to that system and retries with a timeout. In this scenario you need to start the receiver at least 1 time.
If this is not an option and you want to plug in receiver afterwards, you might want to consider a setup of your messages which allows you to retrieve the full state, i.e. if you send total-messages instead of differential- messages.
After a little google, I came upon this definition durable subscribers, I hope this helps:
See:
http://activemq.apache.org/how-do-durable-queues-and-topics-work.html
and
http://activemq.apache.org/manage-durable-subscribers.html
since you are using C# client i don't konw if this is supported
topic = new ActiveMQTopic("TEST.Topic?consumer.retroactive=true");
http://activemq.apache.org/retroactive-consumer.html
So, another solution is to configure this behavior on the broker side by adding that to the activemq.xml and restart :
The subscription recovery policy allows you to go back in time when
you subscribe to a topic.
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" >
<subscriptionRecoveryPolicy>
<timedSubscriptionRecoveryPolicy recoverDuration="10000" />
<fixedCountSubscriptionRecoveryPolicy maximumSize="10000" />
</subscriptionRecoveryPolicy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
http://activemq.apache.org/subscription-recovery-policy.html
I went around the issue by sending a message from each process when they're launched back to the main one, and then only sending the info I needed to send.

Trade Capture Report - QuickFix

I am sending a Trade capture report request with 35 = AD.
I am getting an acknowledge message back with 35=AQ(TradeCaptureReportRequestAck) and then a series of 35=AE(TradeCaptureReport) messages but I only see them in the log file.
I am not getting any Message back on my fromApp() method. I don’t know if this is the right method that I should be coding my logic for listening a call back from server.
Can you please help here, which callback method I need to implement so that I can listen to the trade capture sent by the server.
Thanks,
Arshya
Yes you use fromApp() after all what other choice is there? Output a debug log message for every message that goes through fromApp and check you see the messages in your debug log.

How can I receive multiple notifications by using GCM without replacing the precedent one?

I'm working on a project which receive notification from GCM server.
I've got the registration ID from GCM server and i send it to my server application which save it in the database.
My device receive the message but when I try to send another one, the precedent is replaced.
I know that we've 2 types of message:
Collapsible "send to sync"
Non-Collapsible
So without changing the name of the message, how can I get two message send at different time?
UPDATE 1:
When my device is offline (for example airport mode activated), I try
to send for example 2 messages from my application server to Google
server (I read that Google stores all the messages). But when I
desactivate this mode, I receive only the last message sent.
I use different collapse_key for different message and I receive all
of them (of course when the device online).
Is anybody knows how can I fix this?
The collapse key is relevant only to messages that were sent to the GCM server but haven't reached the destination device yet (if more than one such message has the same collapse key, only one of them will be sent to the device when it becomes online).
In your question you describe a different situation - the first message is received by the device and then the second message is received by the device and replaces the original message. That has nothing to do with GCM. It has to do with the way your application handles the received messages. For example, if your application code that receives the message displays is as a notification, it's up to you to decide whether a new message will override the existing notification or create a new notification.
You need to make sure that the value of the 'collapse_key' field in each message is different

Categories

Resources