Skip to content

Latest commit

 

History

History
63 lines (56 loc) · 1.84 KB

File metadata and controls

63 lines (56 loc) · 1.84 KB

ReactiveSmppStreams

This is an example of a server-to-server chain implementation where a SMPP (Short Message Peer-to-Peer) client using NIO in a single thread can provide many TCP sessions .

The other asynchronous client using reactive streams (java.util.concurrent.Flow) to communicate with the SMPP client sends messages to the application server.

Thus, communication between many SMSC (Short Message Service Center) and many application servers (or micro services) can be served by only two threads.

connecting to SMSC

ProtocolClient client = SmppClient.builder()
                .bindIp("localhost").host("localhost").port(server.getPort())
                .username("guest").password("secret")
                .systype("ReSmpp").timeout(30 * 1000)
                .maxmps(2)
                .newSession();
client.connect(channelNumber)

processing of PDUs received from all SMSCs.

 client.processing();
 BasePDU pdu;
 while (pdu!= null )  {
    pdu=client.getNextPdu(DEFAUL_READ_TIMEOUT));
 }

sending PDU

 client.send(channelNumber,pdu=new Submit()
                .message("Hello!")
                .setseqId());
 client.close(channelNumber)

SMSC simulator

 server = new TestServer()
          .withPort(port)
          .setPackerParser(new Function() {
              @Override
              public BasePDU apply(ByteBuffer buffer) {
                  return BasePDU.newPDU(buffer);
              }
          }).start();

processing PDUs received from clients

server.setHandler((pdu)->{
              BasePDU resp=switch(pdu.getCommandId()){
                  case BaseOps.BIND_TRANSCEIVER -> new BindResp().of(pdu);
                  default->null;
              };
              return null;
        });