Page 1 of 1
SubmitAsync and MessageId
Posted: Tue Oct 07, 2008 11:26 am
by dspeak
Is it possibe to use SubmitAsync(SubmitSm submit_sm) to send a SMS text *AND* to get the MessageId so that DeliverSm's can be matched up with the original message?
Thanks.
Posted: Tue Oct 07, 2008 2:18 pm
by NickAskew
Hi
(1) I set the SubmitSm.Sequence equal to the unique ID of the row in my table where I manage the message I am sending asynchronously.
(2a) I retrieve the 'posted' to carrier message in the [evSubmitComplete] event [data As ALT.SMS.SubmitSmResp], where I can match this response to the original message by using the returned [data.Sequence].
(2b) I also record the [data.MessageID] returned in the response against the SMS I sent so that I can then match up the delivery receipt which is where things get awry. NOTE: The MessageID provided here is in
Hexadecimal.
(3) I retrieve the message delivery receipt within the [evDeliverSm] event which returns [data As ALT.SMS.DeliverSm], data.UserDataPdu.ShortMessage returns a string which contains (amongst other things) the MessageID returned in the 'post' confirmation in step 2b above in this format [id:TheOrigMessageIDGoesHere] (which according to the SMPPv34 spec is vendor specific!)
This is where you need to pay particular attention because the [id:MessageIDGoesHere] in the SMPPv34 spec says it should be returned in 10 or few characters in DECIMAL format (for example: id:1234567890) but also goes on to say that it is also vendor specific.. I have encountered this value in DECIMAL format per the specification (when using mBlox -
http://www.mblox.com/) and in 10 characters of hexadecimal (Hays -
http://www.hslsms.com/) which requires a lot more storage than 10 digits in decimal!
In my opinion, even though Hays kind of go against the SMPPv34 specification, it certainly makes a lot more sense owing the MessageID being returned initially in the [evSubmitComplete] event.
So in brief, set the data.Sequence when you send the message, retrieve the related MessageID in hex from the [evSubmitComplete] event and then depending on how your particular provider returns the MessageID within the [data.UserDataPdu.ShortMessage] object, either use the MessageID directly to look up your original message in your chosen storage medium else convert the returned 10 digit MessageID into Hexadecimal and use that to find the message.
HTH, Nick
Posted: Fri Oct 10, 2008 10:29 am
by dspeak
Thanks for that Nick.
I've tried it and it seems to work most of the time!
However, for each SMS sent, is the evSubmitComplete guaranteed to fire *before* the first evDeliverSm? i.e. if I send 5000 SMS's asynchronously could I receive a DeliverySM before a submitCompleteSM? If so the database will not have the correct messageId when the DeliverySM arrives because the SubmitSM hasn't been received...
Regards,
David.
Posted: Tue Oct 14, 2008 1:59 pm
by NickAskew
Hi David,
The two providers I am using at the moment (mBlox and Hays) have been returning an evSubmitComplete prior to the evDeliverSm HOWEVER the Formal SMPP v3.4 specification does state that an application sending asynchronously should be able to handle out of order replies.
I have anticipated out of order replies in my application by utilising a Queue (that would be an internal Queue object and not Microsoft Message Queue) whereby I pop each item returned from evSubmitComplete into a queue called evSC, and each returned item from evDeliverSm into a queue called evDS and then have a timer which fires and first empties the evSC queue and then the evDS queue, if it encounters a response in the evDS queue it just pops it back into the queue so that it is checked the next time my queue timer fires. The downside here is that all the responses will be held in memory in a volatile fashion rather than being recorded within SQL immediately which means there could be some data loss in the event of a machine crash. I suppose there is no reason why you couldn't implement the above strategy using Microsoft Message queues so that the messages persist in the event the machine goes down mid operation.
This strategy is also useful in allowing you to serialise access to the database as a previous bad experience has taught me that having multiple threads attempting to perform updates, inserts and selects against the same table (and often targetting the same recently accessed rows) in a db leads to a lot of frustration with table locks and such!
Also while I remember.. mBlox provided me with two server addresses to connect to simultaneously, because of the way they load balance message sending it is possible that you may get a response to a message sent via server 1 from server 2 - I can confirm I have seen this happening.
Regards
Nick
Posted: Fri Oct 17, 2008 9:25 am
by dspeak
Thanks Nick. I'm also using mBlox with two servers, and have the odd problem with empty submitreplys or missing delivery report, so I'll change to an async algorithm and try to capture everything in the right order!
Thanks for your help,
David.
Can Any One share , the sample code for async messaging >
Posted: Mon May 18, 2009 6:51 pm
by yepak
i want to get an idea, how to send asynchronous messages. so kindly tell me the steps ... if possible, sample code
Posted: Tue May 19, 2009 8:13 am
by adrianaitken
yepak - the sample code is when you download this software. Certainly in the VB.Net source code, it clearly shows how to send asynchronus messages.