Giter Club home page Giter Club logo

spring-boot-starter-smpp's Introduction

spring-boot-starter-smpp

Maven Central codecov Travis-CI Conventional Commits

Quality Gate Status Reliability Rating Maintainability Rating Security Rating

Bugs Code Smells Vulnerabilities

Duplicated Lines (%) Lines of Code Technical Debt

This Spring Boot starter can be used by any Spring Boot application that wants to send SMS messages using SMPP. SMPP v3.4 spec

Features

  • Sending message with delivery receipt
  • Sending datagram message (without delivery receipt)
  • Sending silent message
  • Sending flash message
  • Cancel message
  • Multiply SMPP connection
  • SMPP connection load balancing

Usage

Add the following dependency to your project:

Maven:

<dependency>
  <groupId>com.github.mikesafonov</groupId>
  <artifactId>spring-boot-starter-smpp</artifactId>
  <version>latest</version>
</dependency>

Gradle:

dependencies {
    implementation 'com.github.mikesafonov:spring-boot-starter-smpp:latest'
}

Configure spring-boot application via properties (see Configuration section).

Use SenderManager to send SMS:

public class RoundRobinApplicationService {
    private final SenderManager senderManager;

    public void sendMessage(String from, String to, String text) {
        Message message = Message.simple(text)
                .from(from)
                .to(to)
                .build();
        senderManager.getClient().send(message);
    }
}

Configuration

The following tables show the available configuration:

Configuration Description Default
smpp.defaults Default smpp connection properties
smpp.defaults.ucs2Only Using ucs2 encoding only or not false
smpp.defaults.maxTry Number of attempts to reconnect if smpp session is closed 5
smpp.defaults.connectionMode Client connection mode (STANDARD, TEST, MOCK) STANDARD
smpp.defaults.windowSize Smpp connection window size 90
smpp.defaults.loggingPdu Is logging smpp pdu false
smpp.defaults.loggingBytes Is logging smpp bytes false
smpp.defaults.rebindPeriod Connection rebind period (Duration) 90s
smpp.defaults.requestTimeout Request timeout (Duration) 5s
smpp.defaults.allowedPhones Array of phones to send. Using only if connectionMode is TEST []
smpp.defaults.connectionType Type of smpp connections(TRANSCEIVER or TRANSMITTER_RECEIVER) TRANSMITTER_RECEIVER
smpp.connections Map of SMSC connections
smpp.connections.<name>.credentials SMSC connection credentials
smpp.connections.<name>.credentials.host SMSC host
smpp.connections.<name>.credentials.port SMSC port
smpp.connections.<name>.credentials.username SMSC username
smpp.connections.<name>.credentials.password SMSC password
smpp.connections.<name>.ucs2Only Using ucs2 encoding only or not false
smpp.connections.<name>.maxTry Number of attempts to reconnect if smpp session is closed 5
smpp.connections.<name>.connectionMode Client`s connection mode STANDARD see com.github.mikesafonov.smpp.config.ConnectionMode
smpp.connections.<name>.windowSize Smpp connection window size 90
smpp.connections.<name>.loggingPdu Is logging smpp pdu false
smpp.connections.<name>.loggingBytes Is logging smpp bytes false
smpp.connections.<name>.rebindPeriod Connection rebind period (Duration) 90s
smpp.connections.<name>.requestTimeout Request timeout (Duration) 5s
smpp.connections.<name>.allowedPhones Array of phones to send. Using only if connectionMode is TEST []
smpp.connections.<name>.connectionType Type of smpp connections(TRANSCEIVER or TRANSMITTER_RECEIVER)
smpp.connections.<name>.systemType The systemType parameter is used to categorize the type of ESME that is binding to the SMSC.
smpp.setupRightAway Should setup smpp clients after creation and fail fast if connection cant be established true

Configuration example for .properties file:

smpp.connections.one.credentials.host=localhost
smpp.connections.one.credentials.username=user
smpp.connections.one.credentials.password=pass
smpp.connections.one.credentials.port=1111
smpp.connections.two.credentials.host=localhost
smpp.connections.two.credentials.username=user2
smpp.connections.two.credentials.password=pass2
smpp.connections.two.credentials.port=2222

Configuration example for .yaml file:

smpp:
    default:
        maxTry: 10
        ucs2Only: true
    connections:
        one:
           credentials:
                host: localhost
                username: user
                password: pass
                port: 1111
        two:
           credentials:
                host: localhost
                username: user2
                password: pass2
                port: 2222

Build

Build from source

You can build application using following command:

./gradlew clean build -x signArchives

Requirements:

JDK >= 1.8

Unit tests

You can run unit tests using following command:

./gradlew test

Mutation tests

You can run mutation tests using following command:

./grdlew pitest

You will be able to find pitest report in build/reports/pitest/ folder.

Integration tests

You can run integration tests using following command:

./grdlew testIntegration

Key abstractions

This starter provides several abstractions:

SenderClient

This interface represents smpp protocol TRANSMITTER or TRANSCEIVER (see connectionType property) client. This is entry point to sending any messages. Spring-boot-starter-smpp comes with several implementations:

class diagram

DefaultSenderClient

This is default implementation. DefaultSenderClient creates real smpp connection and performing all requests.

TestSenderClient

TestSenderClient should be used for testing purpose. TestSenderClient client may provide real smpp connection via proxy implementation of SenderClient. Every incoming request will be redirected to real SenderClient only if destination phone contains in list of allowed phone (smpp.connections.<name>.allowedPhones property). Otherwise response will be generated by SmppResultGenerator.

MockSenderClient

MockSenderClient does not perform any connection via smpp and only generate response using SmppResultGenerator.

SmppResultGenerator

Implementations of this interface is used by MockSenderClient and TestSenderClient clients to generate request response.

Starter by default use AlwaysSuccessSmppResultGenerator which always generate success response with random smsc message id.

You can implement own SmppResultGenerator to add custom logic.

TypeOfAddressParser

DefaultSenderClient use implementation of TypeOfAddressParser to detect TON and NPI parameters for source and destination address of message. Starter provide DefaultTypeOfAddressParser and UnknownTypeOfAddressParser implementations.

By default starter use DefaultTypeOfAddressParser. DefaultTypeOfAddressParser supports international and alphanumeric ton parameters, otherwise return UNKNOWN ton/npi.

UnknownTypeOfAddressParser always return UNKNOWN ton/npi. This means what your SMS center must detect this parameters by himself.

ResponseClient

This abstraction represent connection via SMPP with RECEIVER or TRANSCEIVER (see connectionType property) type. Key purpose is listening delivery receipts. By default starter use DefaultResponseClient. This class keeping smpp connection and pushing all incoming PDU to SmppSessionListener.

SmppSessionListener

This class dedicated to listening all incoming PDU traffic. By default starter use ResponseSmppSessionHandler. This class find delivery receipts and push to DeliveryReportConsumer.

DeliveryReportConsumer dedicated to handle DeliveryReport on client side. Client may build custom logic on receiving delivery receipts by implementing this interface. Starter use by default NullDeliveryReportConsumer if client doesnt provide any implementation of DeliveryReportConsumer. NullDeliveryReportConsumer ignore any delivery receipts.

You can use custom SmppSessionListener by creating appropriate bean.

SenderManager

This is high level abstraction over sender clients.

class diagram

This starter comes with one default implementation - StrategySenderManager. StrategySenderManager holds list of smsc connections and return sender client based on some rules which implemented by IndexDetectionStrategy

There are two default implementation of IndexDetectionStrategy - RandomIndexDetectionStrategy(return random sender client) and RoundRobinIndexDetectionStrategy (return sender client based on round and robbin algorithm). RoundRobinIndexDetectionStrategy strategy used by default.

Contributing

Feel free to contribute. New feature proposals and bug fixes should be submitted as GitHub pull requests. Fork the repository on GitHub, prepare your change on your forked copy, and submit a pull request.

IMPORTANT!

Before contributing please read about Conventional Commits / Conventional Commits RU

spring-boot-starter-smpp's People

Contributors

dependabot-preview[bot] avatar mikesafonov avatar mikhailepatko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spring-boot-starter-smpp's Issues

Want to contribute

Would like to contribute to this library. Send me your email Id. Sorry for adding this message as an issue.

Is this project still active?

I see the last (real) commit is from over a year ago. Is this still a relevant/wanted project?
If so I can contribute, I have Java and SMPP knowledge.

Message validity period

Hi,
firstly I'd like to thank you for your great library :)

I've got a question if it's possible to set validity period (smsc expiration time) for the message?

Greetings,
cholo

failed message in bind request with reason “ESME has maxed out its allowed sessions”

I found that there are a lot of failed message in bind request with reason “ESME has maxed out its allowed sessions”. Currently, we set the maximum sessions as 10 in each site. But it seems your application will bind more than 20 sessions to submit SMS. For the submissions, you can use the same sessions to submit 200 messages/second (your production accounts are using this logic) instead to bind X sessions to submit 200 messages/second.

how can i setting for : maximum sessions as 10 in each site.

toReport method should not check missing fields

Hi @MikeSafonov

Current when trying to receive an inbound mo I get the following exception. Sometimes an smsc doesn't return a message with an id therefore it fails here

com.cloudhopper.smpp.util.DeliveryReceiptException: Unable to find [id] field or empty value in delivery receipt message
	at com.cloudhopper.smpp.util.DeliveryReceipt.parseShortMessage(DeliveryReceipt.java:510) ~[ch-smpp-5.1.0-113.jar!/:5.1.0-113]
	at com.cloudhopper.smpp.util.DeliveryReceipt.parseShortMessage(DeliveryReceipt.java:365) ~[ch-smpp-5.1.0-113.jar!/:5.1.0-113]
	at com.cloudhopper.smpp.util.DeliveryReceipt.parseShortMessage(DeliveryReceipt.java:349) ~[ch-smpp-5.1.0-113.jar!/:5.1.0-113]
	at com.github.mikesafonov.smpp.core.reciever.ResponseSmppSessionHandler.toReport(ResponseSmppSessionHandler.java:65) ~[spring-boot-starter-smpp-1.4.0.jar!/:na]

Could you kindly change it to this.

private DeliveryReport toReport(DeliverSm deliverSm) throws DeliveryReceiptException {
        byte[] shortMessage = deliverSm.getShortMessage();
        String sms = new String(shortMessage);
        DeliveryReceipt deliveryReceipt = DeliveryReceipt.parseShortMessage(sms, DateTimeZone.UTC, false);
        return DeliveryReport.of(deliveryReceipt, clientId);
    }

Edit:

Finally found the issue is related to an MO message. When it is parsed the body doesn't contain delivery receipt but instead contains an actual message.

Was able to add the following to ResponseSmppSessionHandler

public class ResponseSmppSessionHandler extends DefaultSmppSessionHandler {

    private final String clientId;
    private final List<DeliveryReportConsumer> deliveryReportConsumers;
    private final List<ReceivedMessageConsumer> receivedMessageConsumers;

    public ResponseSmppSessionHandler(String clientId, List<DeliveryReportConsumer> deliveryReportConsumers, List<ReceivedMessageConsumer> receivedMessageConsumers) {
        this.clientId = requireNonNull(clientId);
        this.deliveryReportConsumers = requireNonNull(deliveryReportConsumers);
        this.receivedMessageConsumers = requireNonNull(receivedMessageConsumers);
    }

    @Override
    public PduResponse firePduRequestReceived(PduRequest pduRequest) {
        log.debug(pduRequest.toString());
        if (isDelivery(pduRequest)) {
            processReport(pduRequest);
        }

        return pduRequest.createResponse();
    }

    private boolean isDelivery(PduRequest pduRequest) {
        return pduRequest.isRequest() && pduRequest.getClass() == DeliverSm.class;
    }

    private void processReport(PduRequest pduRequest) {
        DeliverSm dlr = (DeliverSm) pduRequest;
        try {
            if(dlr.getEsmClass() == 0x04){
                DeliveryReport report = toReport(dlr);
                for (DeliveryReportConsumer deliveryReportConsumer : deliveryReportConsumers) {
                    deliveryReportConsumer.accept(report);
                }
            }
            else{
                ReceivedMessage receivedMessage = toReceivedMessage(dlr);
                for (ReceivedMessageConsumer consumer: receivedMessageConsumers){
                    consumer.accept(receivedMessage);
                }
            }

        } catch (DeliveryReceiptException e) {
            log.error(e.getMessage(), e);
        }
    }

    private ReceivedMessage toReceivedMessage(DeliverSm deliverSm){
        ReceivedMessage receivedMessage = new ReceivedMessage();
        receivedMessage.setText(new String(deliverSm.getShortMessage()));
        receivedMessage.setSource(deliverSm.getSourceAddress().getAddress());
        receivedMessage.setMsisdn(deliverSm.getDestAddress().getAddress());
        receivedMessage.setMessageId(Integer.toString(deliverSm.getSequenceNumber()));
        return receivedMessage;
    }

    private DeliveryReport toReport(DeliverSm deliverSm) throws DeliveryReceiptException {
        byte[] shortMessage = deliverSm.getShortMessage();
        String sms = new String(shortMessage);
        DeliveryReceipt deliveryReceipt = DeliveryReceipt.parseShortMessage(sms, DateTimeZone.UTC, false);
        return DeliveryReport.of(deliveryReceipt, clientId);
    }
}

Flash Message Feature

Hi Mike,

Hope you are doing well. I have been using your project from last 2 months in my production system. It fulfilled many of my business requirements. A great work. Really appreciated. My question is can you please add new feature to send a flash message.

Regards,
Haseeb Majeed

recieve issue

If the user send message to shortcode, like order something, then how to get this message by host,port,systemId,password etc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.