使用JSMPP短信接收有时会停止

时间:2012-09-20 03:46:10

标签: java sms smpp jsmpp

我正在使用Google的JSMPP从SMS服务中心接收短信。有时,我的程序停止从SMSC接收短信,我必须关闭程序并重新打开程序。然后来自SMSC的排队短信开始接收。这种情况发生在一段时间后,比如7或8小时后。这是我使用的代码

  

SMPP初始代码

l.info("SMPP Initialization");

SMPPSession s = new SMPPSession();

s.setMessageReceiverListener(new Receive(s));


s.connectAndBind(Settings.smsc_host,Settings.smsc_port, BindType.BIND_TRX,
Settings.smsc_user, Settings.smsc_password,Settings.smsc_msg_setting, TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN, null, Settings.smsc_timeout);

ProcessSMS.s = s;

l.info("SMPP Initialization Success");
  

短信接收代码

package sms;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.log4j.Logger;
import org.jsmpp.bean.AlertNotification;
import org.jsmpp.bean.DataSm;
import org.jsmpp.bean.DeliverSm;
import org.jsmpp.bean.MessageType;
import org.jsmpp.extra.ProcessRequestException;
import org.jsmpp.session.DataSmResult;
import org.jsmpp.session.MessageReceiverListener;
import org.jsmpp.session.Session;

import processor.ProcessSMS;

public class Receive implements MessageReceiverListener {

private static final ExecutorService pool = Executors.newFixedThreadPool(10);

private static final Logger l = Logger.getLogger(Receive.class);

private Thread thread;

public Receive(){
super();
}

public Receive(Session s){
this();
}

@Override
public DataSmResult onAcceptDataSm(DataSm arg0, Session arg1)
throws ProcessRequestException {

return null;
}

@Override
public void onAcceptAlertNotification(AlertNotification arg0) {


}

@Override
public void onAcceptDeliverSm(DeliverSm arg0)
throws ProcessRequestException {

l.info("Received SMS " + arg0);



if(MessageType.SMSC_DEL_RECEIPT.containedIn(arg0.getEsmClass())){

}else{
pool.submit(new ProcessSMS(arg0));
//thread = new Thread(new ProcessSMS(arg0));
//thread.start();
}

}

}
  

这是状态更改类

package sms;

import java.io.IOException;

import global.Shared;
import log.SMSCStateLogger;

import org.jsmpp.bean.BindType;
import org.jsmpp.bean.NumberingPlanIndicator;
import org.jsmpp.bean.TypeOfNumber;
import org.jsmpp.extra.SessionState;
import org.jsmpp.session.SMPPSession;
import org.jsmpp.session.Session;
import org.jsmpp.session.SessionStateListener;

import processor.ProcessSMS;
import settings.Settings;

public class StateChange implements SessionStateListener{

private static SMSCStateLogger l  = new SMSCStateLogger(StateChange.class);

private Session s;

@Override
public void onStateChange(SessionState arg0, SessionState arg1, Object arg2) {
//arg0 = new State
//arg1 = old State

if(!arg0.isBound() && arg1.isBound()){
int con = Shared.getNextReConnectInterval();
l.info("State changed from " + arg1 + " to " + arg0 + " on " + arg2);

while(true){
l.info("Re Connection in " + con + " ms");

try{
Thread.sleep(con);
}catch(InterruptedException iex){
l.fatal("Re Connection failed due to exception " + iex);
break;
}

s = new SMPPSession();

((SMPPSession) s).setMessageReceiverListener(new Receive(s));
s.addSessionStateListener(new StateChange());

try{

((SMPPSession) s).connectAndBind(Settings.smsc_host,Settings.smsc_port,  BindType.BIND_TRX,
Settings.smsc_user, Settings.smsc_password,Settings.smsc_msg_setting, TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN, null, Settings.smsc_timeout);

}catch(IOException ioex){
l.fatal("Connection failed due to " + ioex.getMessage());
}

ProcessSMS.s = (SMPPSession) s;

l.info("Re Connection success");

break;


}
}
}

}

有人知道发生了什么事吗?

1 个答案:

答案 0 :(得分:1)

https://github.com/uudashr/jsmpp更新了JSMPP API。

使用git下载源代码 运行mvn install来创建jar存档。