Message Loss while using asynchronous message sending

.NET library for SMPP protocol
majortargets
Posts: 54
Joined: Mon Nov 16, 2009 3:48 pm
Location: United Kingdom
Contact:

Message Loss while using asynchronous message sending

Post by majortargets » Thu Jan 26, 2012 10:52 am

Hello Alt,

I discovered that the number of messages that are not transmitted are more than those that got delivered. I have ran series of test and I don't know if the issue is from operator side or the application. I sent 500 sms with using the code segment below. The code checks if client.Status = Inetlab.SMPP.Common.ConnectionStatus.Bound and picks 10 sms at once and transmit to the smsc. but after the whole 500 is sent only first 200 plus are delivered. No error messages were generated. Please let me know where the problem is likely from


Private Sub sendSyncMessages_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim db As New clientDataContext
Try
Dim textInfo As IQueryable(Of client_outbound)
If prioritize = True Then
textInfo = db.client_outbounds.Where(Function(w) w.State = 0).OrderByDescending(Function(f) f.Priority).Take(10)
Else
textInfo = db.client_outbounds.Where(Function(w) w.State = 0).Take(10)
End If
If textInfo.Count <= 0 Then
Thread.Sleep(SleepTime)
End If
If textInfo IsNot Nothing Then
For Each item In textInfo
Dim res As String = SyncSubmit(item.Originator, item.Destination, item.TextMessage, item.SubmitMode, item.Datacoding)
If res <> "none" Then
db.ExecuteCommand("Update client_outbound SET State={0},TraceID={1},DeliveryStatus={2},DateLast={3} WHERE ID ={4} ", 1, res, "transmitted", Date.Now.ToString, item.ID)
End If
End Select
Next
Else
End If
Catch ex As Exception
AddToLog(ex.ToString)
Finally
db.Dispose()
End Try
End Sub
majortargets
Posts: 54
Joined: Mon Nov 16, 2009 3:48 pm
Location: United Kingdom
Contact:

Re: Message Loss while using asynchronous message sending

Post by majortargets » Fri Jan 27, 2012 6:48 am

Sorry I made a mistake in the code, it is asynchronous sending not synchronous. Here is the code segment

Private Sub sendAsyncMessages_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim db As New clientDataContext
'db.Connection.ConnectionString = MyConnectionString
Try
Dim textInfo As IQueryable(Of client_outbound)
Dim srcTon As Byte = Byte.Parse(tbSrcAdrTON)
Dim srcNpi As Byte = Byte.Parse(tbSrcAdrNPI)

Dim dstTon As Byte = Byte.Parse(tbDestAdrTON)
Dim dstNpi As Byte = Byte.Parse(tbDestAdrNPI)
If prioritize = True Then
textInfo = db.client_outbounds.Where(Function(w) w.State = 0).OrderByDescending(Function(f) f.Priority).Take(10)
Else
textInfo = db.client_outbounds.Where(Function(w) w.State = 0).Take(10)
End If
If textInfo.Count <= 0 Then
Thread.Sleep(SleepTime)
End If
Dim i As Integer = 0

If textInfo IsNot Nothing Then
For Each item In textInfo
client.SubmitTextAsync(GetSubmitMode(item.SubmitMode), srcTon, srcNpi, item.Originator, dstTon, dstNpi, item.Destination, GetDataCoding(item.Datacoding), item.TextMessage)
db.ExecuteCommand("Update client_outbound SET State={0},DeliveryStatus={1},DateLast={2},TraceID={4} WHERE ID ={3} ", 1, "transmitted", Date.Now.ToString, item.ID, "none")
Next
Else
AddToLog("There is nothing in the database")
End If
Catch ex As Exception
AddToLog(ex.Message)
Finally
db.Dispose()
End Try
End Sub
NickAskew
Posts: 60
Joined: Tue Oct 07, 2008 1:35 pm

Re: Message Loss while using asynchronous message sending

Post by NickAskew » Sun Jan 29, 2012 10:58 pm

Hi MajorTargets,

Do you check the command_status of the returned SubmitSmResp? I have noticed one of our providers simply drop the DeliverSm if I attempt to send more messages to them per second than is in our contract - They should send back a throttle response but this provider doesn't support it.

Some command_status states that may indicate your provider cannot handle the speed you are sending them messages include:
ESME_RMSGQFUL 0x00000014 Message Queue Full
ESME_RSUBMITFAIL 0x00000045 submit_sm or submit_multi failed
ESME_RTHROTTLED 0x00000058 Throttling error (ESME has exceeded allowed message limits)

Regards

Nick
ProcessFlows UK Ltd
http://www.processflows.co.uk/
majortargets
Posts: 54
Joined: Mon Nov 16, 2009 3:48 pm
Location: United Kingdom
Contact:

Re: Message Loss while using asynchronous message sending

Post by majortargets » Thu Feb 02, 2012 12:24 pm

I just confirmed from the SMSC that they have throttling policy of 200 sms per 10 minute. But the problem is that the application still keeps sending sms without any error message. From the SMS side they only received my first 200 SMS and other ones didnt get to them. They claim that their application do send out throttling error message when it reaches the allowed sms per second but my application don't receive is. Is there anything wrong somewhere.
NickAskew
Posts: 60
Joined: Tue Oct 07, 2008 1:35 pm

Re: Message Loss while using asynchronous message sending

Post by NickAskew » Thu Feb 02, 2012 2:03 pm

Ask the SMSC which PDU they return that contains the Throttle Response.

The SMPP v3.4 Specification says this:

The command_status field of an SMPP message response indicates the success or failure of an SMPP request. It is relevant only in the SMPP response message and should be set to NULL in SMPP request messages.
The SMPP Error status codes are returned by the SMSC in the command_status field of the SMPP message header and in the error_status_code field of a submit_multi_resp message.

So try in the following events, the one I would have expected it to be returned in would be:

Event [SmppClient_evSubmitComplete]
data.Status = ESME_RTHROTTLED

However, also try debugging the following events to see if your provider returns it in a different event:

Event [SmppClient_evAlertNotification]
data.Status = ESME_RTHROTTLED

or

Event [SmppClient_evDataSm]
data.Status = ESME_RTHROTTLED

or

Event [SmppClient_evDeliverSm]
data.Status = ESME_RTHROTTLED

or

Event [SmppClient_evGenericNack]
data.Status = ESME_RTHROTTLED
ProcessFlows UK Ltd
http://www.processflows.co.uk/
majortargets
Posts: 54
Joined: Mon Nov 16, 2009 3:48 pm
Location: United Kingdom
Contact:

Re: Message Loss while using asynchronous message sending

Post by majortargets » Thu Feb 09, 2012 12:39 pm

Hello,

How can I implement SubmitSpeed in my code to throttle messages per seconds e.g 20sms/second. From the documentation, it is given per minute i.e "Number of submits per minute used in the methods SubmitText and AdvancedSubmit. "
NickAskew
Posts: 60
Joined: Tue Oct 07, 2008 1:35 pm

Re: Message Loss while using asynchronous message sending

Post by NickAskew » Thu Feb 09, 2012 2:04 pm

Hi

You will have to implement your own throttling code. Keep a counter going that resets every 1 second, if the counter > 20 then pause 10ms and check again.

Cheers
Nick
ProcessFlows UK Ltd
http://www.processflows.co.uk/
majortargets
Posts: 54
Joined: Mon Nov 16, 2009 3:48 pm
Location: United Kingdom
Contact:

Re: Message Loss while using asynchronous message sending

Post by majortargets » Wed Feb 29, 2012 11:56 am

Hello Alt,

Some of the messages I am sending to SMSC using the async method id returning throttled error message. I have been looking for a best way to pick throttled message out of the bulk i sent to the SMSC but since I cant assign an ID to it when sending. Please how to i trace each message so that i can resend undelivered/throttle ones. Below is the sample log
2/29/2012 10:06:14 AM: SubmitSmResp received. Status: ESME_ROK, Message Id: 2b83f80f, Sequence: 319418417
2/29/2012 10:06:14 AM: SubmitSmResp received. Status: ESME_ROK, Message Id: 59ee10be, Sequence: 319418424
2/29/2012 10:06:26 AM: SubmitSmResp received. Status: ESME_RTHROTTLED, Message Id: a8a5dde3-90a1-4cf8-bbcf-1efa9cf7f8f9, Sequence: 319418487
2/29/2012 10:06:26 AM: SubmitSmResp received. Status: ESME_RTHROTTLED, Message Id: b05fcdd1-5857-4eb9-af14-d0b5cfc970b4, Sequence: 319418488
2/29/2012 10:06:26 AM: SubmitSmResp received. Status: ESME_RTHROTTLED, Message Id: 1e064d04-4929-462a-93da-d8566c062dfd, Sequence: 319418489
NickAskew
Posts: 60
Joined: Tue Oct 07, 2008 1:35 pm

Re: Message Loss while using asynchronous message sending

Post by NickAskew » Wed Feb 29, 2012 12:34 pm

Hi Major

The ESME_RTHROTTLED is returned with the Message Id and Sequence number. When you send any message you always receive a unique identifier (Message Id) from the SMSC, you need to store this alongside the message in your (sql table? - I use the unique id of each message record as the sequence number I submit) message store so that you can flag it as requiring resending when you receive the ESME_RTHROTTLED message back from the SMSC. This is the ONLY way you can tie up which message generated a throttled response.

Cheers
Nick
ProcessFlows UK Ltd
http://www.processflows.co.uk/
majortargets
Posts: 54
Joined: Mon Nov 16, 2009 3:48 pm
Location: United Kingdom
Contact:

Re: Message Loss while using asynchronous message sending

Post by majortargets » Wed Feb 29, 2012 1:53 pm

Hello Nick,

Its like you are talking about sync method sending which will return ID but I actually sent through async method which doesn't generate give me an ID as at the time of sending.
NickAskew
Posts: 60
Joined: Tue Oct 07, 2008 1:35 pm

Re: Message Loss while using asynchronous message sending

Post by NickAskew » Wed Feb 29, 2012 2:24 pm

Hi Major,

I only use the ASYNC methods myself (for speed).

1) I prepare my message to send using InetLab, this splits the message into 1 or more parts that are required.
2) I store the 1 or more parts in a 'messagesend' sql table, and use the unique record id of each message to set the 'sequence number' of each part prior to passing it to the SMSC.
3) SMSC returns a response for each message part sent, the response contains the SMSC 'message id' AND my sequence number, I update my 'messagesend' table to assign the SMSC 'message id' to each part of the message I have sent.
4) When I receive message status updates from the SMSC they pass them back specifying the 'message id' of the message that the SMSC originally told me it associated with my 'sequence number', I can then update the current delivery status of the message I sent by using the 'message id' to search for the message part in my 'messagesend' table.

Regards
Nick
ProcessFlows UK Ltd
http://www.processflows.co.uk/
majortargets
Posts: 54
Joined: Mon Nov 16, 2009 3:48 pm
Location: United Kingdom
Contact:

Re: Message Loss while using asynchronous message sending

Post by majortargets » Wed Feb 29, 2012 2:37 pm

Hello Nick,

Can you tell me how many sms/sec you have been able to send using synchronous method.
I really need speed of about 50 sms/sec which sync method cant deliver. The last time i tested I was only able to send 2sms/sec using sync method.Is there anyway i can optimize my code to do better?

Speed is of priority to me.

Regards,
major
alt
Site Admin
Posts: 918
Joined: Tue Apr 25, 2006 9:45 am

Re: Message Loss while using asynchronous message sending

Post by alt » Wed Feb 29, 2012 3:11 pm

Dear Major,

I think the only way is to use async methods (SubmitAsync) together with "complete" events (evSubmitComplete)

Regards,
Alexey
majortargets
Posts: 54
Joined: Mon Nov 16, 2009 3:48 pm
Location: United Kingdom
Contact:

Re: Message Loss while using asynchronous message sending

Post by majortargets » Wed Feb 29, 2012 3:19 pm

Hello Alexey,

I will work with that.

Thanks
NickAskew
Posts: 60
Joined: Tue Oct 07, 2008 1:35 pm

Re: Message Loss while using asynchronous message sending

Post by NickAskew » Wed Feb 29, 2012 3:42 pm

Hi Major,

I only use the async method - Maximum throughput I have attained connected to 'mBlox' is ~250 message parts per second per server, mBlox provide connection to two servers simultaneously so the best I have managed is ~500 message parts per second spread over two 'mBlox' servers communicating through the DMZ.

The speed is ultimately determined by how fast you can prepare the messages and deal with the responses so a highly tuned back end database is essential, the InetLab component is NOT the weakest link in throughout. The solution I have developed is very scalable in that I can add further mBlox accounts and spread the message load over multiple accounts, we currently utilise 6 connections using 3 pairs of 'mBlox' servers and a single connection to 'Hays' for incoming.

Regards

Nick
ProcessFlows UK Ltd
http://www.processflows.co.uk/
Locked