如何使用 cloudhopper 异步发送 deliverS Resp

how to send deliverSmResp with cloudhopper asynchrous

希望大家平安度过这次疫情。

我收到一条来自 SMSC 的短信,我想给他发一条 deliver_sm_resp。

我试着这样实现它:

@Override
public PduResponse firePduRequestReceived(PduRequest pduRequest) {
    logger.warn("***** BIND RECEIVER *****");
    DeliverSm sms = null;

    if ((pduRequest != null) && pduRequest.getName().equals("deliver_sm")) {
        sms = (DeliverSm) pduRequest;
    }   
    if ((pduRequest != null) && pduRequest.getName().equals("enquire_link")) {
        return pduRequest.createResponse();
    }
    if ( sms !=null && (int)sms.getDataCoding() == 0 ) {
        //message content is English
        logger.warn("***** New Message Received *****");
        logger.warn("From: " + sms.getSourceAddress().getAddress());
        logger.warn("To: " + sms.getDestAddress().getAddress());
        logger.warn("Content: " + new String(sms.getShortMessage()));


            DeliverSm deliver = new DeliverSm();
            deliver.setSourceAddress(sms.getSourceAddress());
            deliver.setDestAddress(sms.getDestAddress());
            deliver.setDataCoding(sms.getDataCoding());
            try {
                deliver.setShortMessage(sms.getShortMessage());
            } catch (SmppInvalidArgumentException e) {
                e.printStackTrace();
            }
            deliver.setSequenceNumber(sms.getSequenceNumber());
            //deliver.setCommandLength(sms.getCommandLength());
            deliver.setCommandStatus(sms.getCommandStatus());


            runDeliverSmRespSmppSessionHandler(session, deliver);

    }
    return super.firePduRequestReceived(pduRequest);
}

我像那样异步调用 runDeliverSmRespSmppSessionHandler :

    public class RunDeliverSmRespSmppSessionHandler extends DefaultSmppSessionHandler implements Runnable {
        .
        .
        .
        public void run() {        
                logger.info("welcome to deliver TestSmppSessionHandler RUN");

            sendRequestPdu(session, deliver);
        }
    private void sendRequestPdu(SmppSession session, DeliverSm deliver) {
            logger.info("welcome to deliver TestSmppSessionHandler sendRequestPdu");

            try {
                WindowFuture<Integer,PduRequest,PduResponse> future = session.sendRequestPdu(deliver, 10000, false);
                if (!future.await()) {
                    logger.error("Failed to receive deliver_sm_resp within specified time");
                } else if (future.isSuccess()) {
                   DeliverSmResp deliverSmResp = (DeliverSmResp)future.getResponse();
                    logger.info("deliver_sm_resp: commandStatus [" + deliverSmResp.getCommandStatus() + "=" + deliverSmResp.getResultMessage() + "]");
                } else {
                    logger.error("Failed to properly receive deliver_sm_resp: " + future.getCause());
                }
            } catch (Exception e) {
                logger.error("message catched in smDeliver : "+e.getMessage()+" get stackTrace : "+e.getStackTrace());

            }
        }

不幸的是,我在 sendRequestPdu() 中遇到了这个错误:

04-04-2020 23:15:41 ERROR TestSmppSessionHandler:61 - Failed to receive deliver_sm_resp within specified time
04-04-2020 23:16:06 WARN  EnquireLinkTask:37 - Enquire link failed, executing reconnect: 
com.cloudhopper.smpp.type.SmppTimeoutException: Unable to accept offer within [10000 ms] (window full)
    at com.cloudhopper.smpp.impl.DefaultSmppSession.sendRequestPdu(DefaultSmppSession.java:508)
    at com.cloudhopper.smpp.impl.DefaultSmppSession.sendRequestAndGetResponse(DefaultSmppSession.java:464)

感谢您的帮助

要发送回复通知 SMSC,您必须使用

   private void sendResponsePdu(SmppSession session, DeliverSmResp deliver) {
        logger.info("welcome to deliver TestSmppSessionHandlerV2 sendRequestPdu");

          try {
              session.sendResponsePdu(deliver);
              logger.info("message deliver response sent successfully !!!");

          } catch (Exception e) {
            logger.error("message catched in smDeliver : "+e.getMessage()+" get stackTrace : "+e.getStackTrace());

          }

关于DeliverSmResp deliver,你可以这样初始化:

            DeliverSmResp deliver_sm_resp = new DeliverSmResp();

            deliver_sm_resp.setCommandLength(17);
            deliver_sm_resp.setCommandStatus(sms.getCommandStatus());
            deliver_sm_resp.setSequenceNumber(sms.getSequenceNumber());
            deliver_sm_resp.setMessageId("");