davideuler / jsmpp

Automatically exported from code.google.com/p/jsmpp
Apache License 2.0
0 stars 0 forks source link

Connection failing frequently #73

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi uudashr,
  I am developing a sms application using jsmpp version 2.1 for sending and receiving sms messages  using Bind Type as TRX .  My problem is  after the initial connection is made the smpp session state gets unboound after some time . The  time for unbinding is not consistent . I went through the API and found that after initial connection the   follwing code using a thread  in the SmppSession.class is used for sending the keep alive messages( EnquireLink  messages) .

private class EnquireLinkSender extends Thread {
        private final AtomicBoolean sendingEnquireLink = new AtomicBoolean(false);

        @Override
        public void run() {
            logger.info("Starting EnquireLinkSender");
            while (isReadPdu()) {
                while (!sendingEnquireLink.compareAndSet(true, false) && isReadPdu()) {
                    synchronized (sendingEnquireLink) {
                        try {
                            sendingEnquireLink.wait(500);
                        } catch (InterruptedException e) {
                        }
                    }
                }
                if (!isReadPdu()) {
                    break;
                }
                try {
                    sendEnquireLink();
                } catch (ResponseTimeoutException e) {
                    close();
                } catch (InvalidResponseException e) {
                    // lets unbind gracefully
                    unbindAndClose();
                } catch (IOException e) {
                    close();
                }
            }
            logger.info("EnquireLinkSender stop");
        }

 I am using  spring  to load the method for getting the initial connection to the smsc and the application is running as a web apllication in jboss 4.2  .The session is reconected when  the session gets unbound .
(Code file is attached )
connectionProvider = SmsConnectionProviderFactory
             .getServiceProvider(SmsServiceProvider.PROVIDER_TYPE_HUTCH);
        messageExecutorService = Executors.newFixedThreadPool(Integer.valueOf(2));
        LoggingLevel.enableLoggingLevels(Integer.valueOf(2));
        try{
            connectionProvider.connectAndBind();
            connectionProvider.getSession().setMessageReceiverListener(
                    new HutchSmsMessageListener(messageService,connectionProvider,messageExecutorService));
            connectionProvider.getSession().addSessionStateListener(
                    new SessionConnectivityListener(messageService,connectionProvider,messageExecutorService));
        }catch(IOException e){
            if (SmsEventLogger.isEnabled(LoggingLevel.WARN)) {
                 SmsEventLogger.logException(LoggingLevel.FATAL,SmsApplicationEvents.EXCEPTION,e);
          }
          }

 My problem is though the  session is getting  rebound using a new Session (The code files are attached with this mail )  the frequency of  getting unbound is not acceptable for the application( Some messages are getting lost  due to this ) .Is there any way that I can prevent this  by using a separate thread for sending the enquirer links? If there is  be helpful if you provide  me  a sample .
Is there any property ar any other method for controlling this in the jsmpp API 
.

Would appreciate greatly if you could help me .

Regards,
Kolitha.

Original issue reported on code.google.com by kolitha....@gmail.com on 9 Jun 2010 at 4:02

Attachments:

GoogleCodeExporter commented 9 years ago
Hi Holitha

Once your session/connection get bounce ,you are creating a new SMPPSession 
,But it will cause to intaniate a new Sequence No inside the SMPPSession ,So it 
is possible that your SMSC may get duplicate PDU for same command that could be 
the reason lose out some of your request .
So my Suggestion would be get the sequence number (If you want use the oracle 
sequence OR mysql AUTO _INCREMEENT) from the relational database 

Cheers,
Dominic

Original comment by dominic....@gmail.com on 23 Jun 2010 at 2:14

GoogleCodeExporter commented 9 years ago
Hi kolitha, 

Unbound loosing session is a common thing. To know why it does happen, you 
should investigate via log or capture the TCP packet.
You still can avoid getting lost of your message. When submit message is 
success, no exception and you get message id as return, then there is no error. 
But when there is an exception occurred, then you have to retry the message 
submission on the new session. Also you need to keep a number of outstanding 
message, for an example: do not send another message if you already have 10 
message having no response yet. Why, the connection or SMSC might busy or in a 
problem, so keeping 10 outstanding message would be more wise and easier to 
manage.
So the point is:
1. Connection loss is a common (but you still need to investigate the cause)
2. Design a retry mechanism
3. Define a number of outstanding message, and do not send another message if 
the outstanding message has reach it maximum limit.

I hope this can help

Original comment by uuda...@gmail.com on 23 Jun 2010 at 3:05

GoogleCodeExporter commented 9 years ago
I am also having trouble with loosing the connection. 
My side is (with jSMPP) is after some time loosing the connection and going 
from bound to closed, when I try to rebind I get a negative response saying 
that I am already bound, so it seems that the connection is only getting 
unbound on my side. 

I set up a session state listener and try to unbind the link when my state 
changes, but this is not working. 

Any hints on why is the connection getting lost ? 
I traced tcp flow and find that enquire links are working just fine and still 
can't find the reason for this, perhaps it is some timeout issue

Original comment by marcel...@gmail.com on 5 Oct 2010 at 12:06