gosmpp icon indicating copy to clipboard operation
gosmpp copied to clipboard

Relating submitted message with message id

Open tahseenjamal opened this issue 1 year ago • 11 comments

When I submit a message, all I get to know if there was an error or not

If not then there would be submit response that I would receive via handler.

In a multi threaded scenario, how would I know for which number and message that I submitted is related to which message ID ?

tahseenjamal avatar Dec 23 '23 14:12 tahseenjamal

Its up to the user to implement this.

I use a map and store the PDU SequenceNumber as the KeyType. When I receive a response, I just get the value with the resp sequence number. Something like this: map[int32]Request

type Request struct{
    OrignalPDU *PDU
    SubmitTime  Time
    ....
}

I also use the map lenght as a Bind window.

Don't forget that Golang map is not thread safe, so you'll also need to manage your access .

laduchesneau avatar Dec 23 '23 16:12 laduchesneau

How do you get the sequence number when you are submitting your message using transceiver ? Because it only returns error status or else nil

tahseenjamal avatar Dec 23 '23 17:12 tahseenjamal

You have access to the sequence number that will be used before you send the PDU on the connection.

When you create a PDU with its New function, like NewSubmitSm(), it calls newbase() and that calls AssignSequenceNumber().

laduchesneau avatar Dec 23 '23 17:12 laduchesneau

Ok this works for short message well.

Also, I was testing with long message where Split is called

submitSMs, err := submitSM.Split()

There is only 1 item in the array, even when the message is 400 characters on

tahseenjamal avatar Dec 23 '23 18:12 tahseenjamal

hey @tahseenjamal how did you managed to set your custom sequence number? can we add our own custom number to the sequence number to submitSM PDU and receive the same on submitSMRESP and deliverSM?

bluewithanas avatar Dec 27 '23 12:12 bluewithanas

Yes you can, while creating NewSubmitSM for submitting you add property called SequenceNumber to it. below is the sample for the same

submitSM := pdu.NewSubmitSM().(*pdu.SubmitSM) 
submitSM.SequenceNumber = 1 // any int32 value
if err := transceiver.Submit(submitSM); err != nil {
      logger.Log.Error("could not send message " + err.Error())
}

Here 1 is sequence number which you can keep any int32 value.

NitinHsharma avatar Dec 27 '23 14:12 NitinHsharma

thanks! @NitinHsharma I can manuallly add sequence number so it solves, the problem for mapping!

but one thing, i see here is whole process is totally async and i find it quite difficult to move data around! My use case is i exposed an API upon which it triggers sends and hit submitSM command.

now, all the PDU driven work is in handlePDU function which is triggered when any onPDU receives something.

How do i move my data let say a webhook URL coming from API body inside the handlePDU function. i feel things are quite tightly coupled here.

bluewithanas avatar Dec 27 '23 17:12 bluewithanas

also @NitinHsharma are you aware if this is the case where for the same message , on DeliverSM delivery receipt, we dont get the same sequence number? i am getting a different one in the headers.

bluewithanas avatar Dec 27 '23 18:12 bluewithanas

Hey @bluewithanas for data moving, actually you can't move the data (as per my understanding) but you can cache it somewhere like gocache or redis based on your use case with key as sequence number. And while getting submitMsg_res you can get it from cache using key.

for second question, i never saw different sequence number in resposne header, might be you are adding it on wrong place while submitting, why cant you just try to use the lib generated sequence number itself boz that also do incr on int32 internally.

NitinHsharma avatar Dec 28 '23 06:12 NitinHsharma

hey @tahseenjamal how did you managed to set your custom sequence number? can we add our own custom number to the sequence number to submitSM PDU and receive the same on submitSMRESP and deliverSM?

@bluewithanas SubmitSM automatically generates the sequence number else you can call its methods call set sequence

tahseenjamal avatar Dec 28 '23 19:12 tahseenjamal

https://github.com/tahseenjamal/smpp_client/blob/master/main.go

You can go through the code that I wrote, in this you can see at the bottom, where the SubmitSM is prepared, I print sequence number. You can also call set sequence function of SubmitSM

also you can see the SubmitSMResp handler getting sequence number as well as messageid

and in delivery report you get messageid, you this way you can crack the puzzle of tracking the message life cycle

tahseenjamal avatar Dec 28 '23 19:12 tahseenjamal

thank you @tahseenjamal

bluewithanas avatar Jan 17 '24 11:01 bluewithanas