Async post to Amazon's SQS - c#

I'd like to send messages to Amazon's SQS in a "launch and forget" mode (it's OK for some messages to get lost).
Today, I use this sync code:
webClient.UploadValues(uri, "POST", data);
Since this is going to be heavily used, I want to change this to an async method.
Is there a way to do this (either using plain .net or AWS SDK)?

Found the reason UploadValuesAsync didn't work: It was missing a content-type header:
http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/MakingRequests_MakingQueryRequestsArticle.html#POSTRequests

Related

How to send message using Tibco RV to asynchronous way?

Currently, I make the Server to send the message using Tibco RV 8.5 version.
I used NetTransport to send the message.
However, I get request to send all message to async way.
So, I look through the document, but there's no way to send the message to asynchronous way in Tibco RV 8.5 version.
How can I send the message async way using Tibco RV?
I would appreciate it if you could let me know by reference or link.
Thanks in advance.
https://docs.tibco.com/pub/rendezvous/8.6.0/doc/pdf/TIB_rv_8.6.0_dotnet_reference.pdf?id=5
I look through the related document, but every SendRequest library send message in synchronous way.
If Tibco RV doesn't provide async method, I want to know how to send the message to async way.
Thanks in advance.

Why does my Twilio MessagingResponse not work?

The following Twilio code doesn't work. This is my webhook handler in an ASP.NET (Core) 6.0 app.
[AllowAnonymous]
[HttpPost]
[Route("webhook-url")]
public IActionResult PostTwilioMessageReceived([FromForm] TwilioMessageReceivedFormModel formModel)
{
// logging code etc.
var response = new Twilio.TwiML.MessagingResponse();
response.AddText($"You sent '{formModel.Body}' but our systems are dumb and can't process this yet.");
return new TwiMLResult(response);
}
There are no errors. I don't receive the message, and my delivery status webhook doesn't appear to be called.
The method above is called as I see it in my logs.
Note - There is no "to" address. I have adapted sample code from Twilio's documentation which also does nothing to either read the sender address or configure the response with a recipient or other correlation ID.
https://www.twilio.com/docs/whatsapp/tutorial/send-and-receive-media-messages-whatsapp-csharp-aspnet#generate-twiml-in-your-application
I've modified my logging to make doubly sure my webhook is being called. It is. And in Twilio's log there's no acknowledgement of the reply my webhook attempts to produce.
To be clear, the code above is using Twilio's libraries.
The TwiML output of your application would be:
<Response>You sent '...' but our systems are dumb and can't process this yet.</Response>
Unfortunately, that isn't valid TwiML, instead it should look like this:
<Response>
<Message>You sent '...' but our systems are dumb and can't process this yet.</Message>
</Response>
This will respond with a message to the sender. To do this, use the .Message method instead of .AddText:
response.Message($"You sent '{formModel.Body}' but our systems are dumb and can't process this yet.");
Everything else looks fine in your code AFAIK.
Aside: If all you need to do is to respond to the current sender with a single message, you can also respond with plain text and the text/plain content type.
Edit by OP
I also changed the return line to:
return this.TwiML(response);
Which was the advice of Twilio support. I didn't try it my original way, but assumed that if there was some kind of magic that's pre-addressing the response, or correlating it in some way, then it might be in using the helper function on the base controller. Thanks.
It's hard to say what caused this without seeing an error or message log. You should be able to see something in the "Monitor" in the console (more details here).
I've had similar issues in the past with Node.js and the problem was there that I forgot to set the content-type of the response to text/xml. But I'm not sure if this is required in your C# code.

Is there a way to make Azure WebJobs ServiceBus out parameter optional?

I am building a console application that will be run as a continuous Azure WebJob. I am using the Azure WebJobs SDK via the Nuget Package Microsoft.Azure.Jobs.ServiceBus v0.3.1-beta (prerelease). I have static method that triggers on an Azure ServiceBus queue. I do some processing and then want to have the option to send a response via the output parameter to another queue. The method signature looks like this:
public static void TriggerOnQueue(
[ServiceBusTrigger(QueueName)] BrokeredMessage receivedMessage,
[ServiceBus(QueueResponseName)] out BrokeredMessage responseMessage)
{
...
}
My initial thought was to set the responseMessage to null. However, when I do this an error appears in the console window. It doesn't stop execution (so it technically does what I want it to do), but I would rather not push something throwing errors to production. Is there any non-hackish way to set a value in the response message that will not throw an error, but will not submit the message to the response queue?
If not, is there another pattern I am missing that I could use? I would prefer to use the pipeline feature of the WebJobs SDK as opposed to creating the output queue manually. I could probably submit the requests that need a response on to a separate queue and have 2 separate triggers, but with the small amount I am having this do I would rather keep it simple and together.
Thoughts?
This pattern of specifying null for an out parameter works for Azure Queues but it throws an exception for Service Bus Queues. This looks like bug in the SDK. I will open a bug for us to fix it. Thank you for reporting this issue

c# app: Is it possible to implement a JSON interface?

I've built a simple C# app (.Net 4.0 + WPF) which can send and receive JSON messages via TCP sockets.
As a next step, it should be possible that JavaScript apps on websites and PHP scripts can send and receive JSON messages to/from my app. Is that possible?
Since JS/PHP will use stateless HTTP connections, how should a request to my app work, for example, should the JS/PHP apps send a JSON message to my app and my app response (HTTP response) with a JSON message? Is that even possible? And should I use GET or POST method to send the JSON messages to/from my app?
Hope my questions do not cause too much confusion ;-) I but I appreciate every tip, clarification or feedback you can give me.
Mike
You can accomplish this via a .NET web service using special JSON directives on the web method, e.g.
[ScriptMethod(UseHttpGet = true, ResponseFormat=ResponseFormat.Json)]
public string DoSomething(string param1, int param2)
{
// Do Something
}
When the ResponseFormat.Json property is specified, the data returned will be serialized into the appropriate JSON format. Also note, in order to recieve a true JSON response, you'll need to set your content-type to "application/json" from the requesting application. Otherwise, the method will attempt to wrap the response in XML.
Also, I am enabling a HttpGet on this method so that you can post via a query string to the method, e.g.
http://www.example.com/service.asmx?param1='Hello'&param2=1;

Can anyone recommend any good UK based SMS gateways for sending and receiving SMS using C#?

Has anyone used any in the UK, and if so, were they any good?
Clickatell is a popular SMS gateway. It works in 200+ countries.
Their API offers a choice of connection options via: HTTP/S, SMPP, SMTP, FTP, XML, SOAP, COM Object.
The HTTP/S method is as simple as this: http://api.clickatell.com/http/sendmsg?to=NUMBER&msg=Message+Body+Here (Clickatell API Guide).
The SMTP method consists of sending a plain-text e-mail to: sms#messaging.clickatell.com, with the following body:
user: xxxxx
password: xxxxx
api_id: xxxxx
to: 448311234567
text: Meet me at home
As for incoming SMSes, you would have to expose an interface through: HTTP, SMPP, SOAP or FTP. For example if you use the HTTP GET and you provide this URL to Clickatell: http://www.yourdomain.com/sms/sms.asp, then Clickatell will send you this HTTP GET with every incoming SMS:
https://www.yourdomain.com/sms/sms.asp?
api_id=12345&
from=279991235642&
to=27123456789&
timestamp=2008-08-0609:43:50&
text=Hereisthe%20messagetext&
charset=ISO-8859-1&
moMsgId=b2aee337abd962489b123fda9c3480fa
You can also test the gateway (incoming and outgoing) for free from your browser: "Test SMS Gateway".
TM4B offer an easy-to-use web-based API, but there are some limitations to what kind of content it can be used for (nothing to do with music, gambling, drinking), BulkSMS is also quite highly regarded and, once again, offer a very simple web-based API.
I've used both before (we have an SMS provider abstraction library create in-house) and both are as reliable as the underlying transport (SMS is not a guaranteed communication method, so messages can go astray).
We use AQL. They arent the cheapest but never had a single issue. We only use for outgoing however so I cant speak for inbound. Simple to use in .NET. Great web interface too.

Categories