Skip to content

Instantly share code, notes, and snippets.

@farirat
Created April 27, 2015 14:09
Show Gist options
  • Save farirat/efc604070f34ef699c8b to your computer and use it in GitHub Desktop.
Save farirat/efc604070f34ef699c8b to your computer and use it in GitHub Desktop.
This will publish a DeliverSM directly to the smpps thrower
from twisted.internet import defer, reactor
from jasmin.vendor.smpp.pdu.operations import DeliverSM
from jasmin.queues.configs import AmqpConfig
from jasmin.queues.factory import AmqpFactory
from jasmin.routing.jasminApi import SmppServerSystemIdConnector
from jasmin.routing.content import RoutedDeliverSmContent
from jasmin.queues.test.test_amqp import waitFor
@defer.inlineCallbacks
def connect_and_publish(pdu, dc):
# AMQP client object
config = AmqpConfig()
config.reconnectOnConnectionLoss = False
amqp = AmqpFactory(config)
# Connect
yield amqp.connect()
# Wait for channel to get ready
yield amqp.getChannelReadyDeferred()
# Prepare content to be published
# scid (Source connector id) and msgid are not needed, just set them to any value
# dc (destination connector) is all what you need
content = RoutedDeliverSmContent(deliver_sm = pdu,
msgid = '1',
scid = 'whatever',
dc = dc,
)
# Publish the pdu
yield amqp.publish(exchange='messaging', routing_key="deliver_sm_thrower.smpps", content=content)
# Wait 2s and disconnect
yield waitFor(2)
yield amqp.disconnect()
# Exit
reactor.stop()
if __name__ == '__main__':
"""
The below 'pdu' is published to RabbitMQ so the deliverSmThrower can take care of it and
send it to the destination connector pointed in 'dc'.
Note:
- Jasmin must be already running before executing this script
- 'dc' must be connected and bound at least with TRX or RX.
Troubleshooting:
- Check /var/log/jasmin/deliversm-thrower.log for any delivery error
"""
dc = SmppServerSystemIdConnector('system_id')
pdu = DeliverSM(
source_addr='1234',
destination_addr='4567',
short_message='any content',
)
# Run !
connect_and_publish(pdu, dc)
reactor.run()
@rahaider
Copy link

i have latest jasmin sms gateway on ubuntu 20 with pythn3, i am getting the following error when i run it on my mtinterceptor
ERROR 790 Executing script on routable (from:b'12345', to:b'54321') returned: <class 'ModuleNotFoundError'>: No module named 'jasmin.queues.test'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment