Simple Message Notification Service (SMN)

The Simple Message Notification service in the Open Telekom Cloud offers three APIs for creating topics (a combination of a message and a logical access point), adding message subscribers and sending out messages. The SMN services includes the two roles publisher and subscriber. In contrast to the Distributed Message Service, a subscriber can also be external: an email address, a telephone number, a message queue or a URL. SMN is easy to integrate with other services and can thus act as an intermediary for data exchange. The service works with redundant message nodes – if one of the nodes fails, another one is used instead. This ensures that the messages are transmitted reliably, regardless of how they are sent. SMN delivers the messages to various end points in a readable format (SMS, email, http/s).

Topic

A topic is a specified event to publish messages and subscribe to notifications. It serves as a message sending channel, where publishers and subscribers can interact with each other.

List Topics

This interface is used to query SMN Topics and to filter the output with query parameters.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')

query = {}
for topic in conn.smn.topics(**query):
    print(topic)

Get Topic

This interface is used to get a SMN topic by ID or an instance of class Topic.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


urn = 'urn:smn:eu-de:123:myname'
topic = conn.smn.get_topic(topic=urn)
print(topic)

Create Topic

This interface is used to create a SMN topic instance with parameters.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


attrs = {
    'name': 'myname',
    'display_name': 'the_display_name'
}
topic = conn.smn.create_topic(**attrs)
print(topic)

Update Topic

This interface is used to update a SMN topic instance with parameters.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


attrs = {
    'name': 'myname',
    'display_name': 'the_display_name3'
}
urn = 'urn:smn:eu-de:123:myname'
topic = conn.smn.get_topic(topic=urn)
topic = conn.smn.update_topic(topic, **attrs)
print(topic)

Delete Topic

This interface is used to delete a SMN topic instance by id or an instance of class Topic.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


urn = 'urn:smn:eu-de:123:myname'
topic = conn.smn.get_topic(topic=urn)
topic = conn.smn.delete_topic(topic)

List Topics Attributes

This interface is used to query SMN topic attributes and to filter the output with query parameters.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


urn = 'urn:smn:eu-de:123:myname'
topic = conn.smn.get_topic(topic=urn)
attributes = conn.smn.topic_attributes(
    topic=topic.id)
for item in attributes:
    print(item)

Update Topic Attribute

This interface is used to update a SMN topic attribute instance with parameters.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


urn = 'urn:smn:eu-de:123:test'
attrs = {}
topic = conn.smn.update_topic_attribute(
    topic=urn,
    name='access_policy',
    **attrs)

Delete Topic Attribute

This interface is used to delete a SMN topic attribute.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


urn = 'urn:smn:eu-de:123:test'
name = 'myattribute'
attribute = conn.smn.delete_topic_attribute(
    topic=urn,
    name=name)
print(attribute)

Subscription

To deliver messages published to a topic to endpoints, you must add the subscription endpoints to the topic. Endpoints can be email addresses, phone numbers, message queues, and HTTP/HTTPS URLs. After you add endpoints to the topic and the subscribers confirm the subscription, they are able to receive messages published to the topic. You can add multiple subscriptions to each topic. This section describes how to add subscriptions to a topic you created or one to which you have been granted permissions and how to delete subscriptions.

List Subscriptions

This interface is used to query SMN Subscription and to filter the output with query parameters.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


for item in conn.smn.subscriptions():
    print(item)

topic = 'topic_urn'
for item in conn.smn.subscriptions(topic=topic):
    print(item)

Create Subscription

This interface is used to create a subscription instance to a SMN topic.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


attrs = {
    'endpoint': '+49123123456789',
    'protocol': 'sms',
    'remark': 'My SMS subscription'
}
topic = 'urn:smn:eu-de:1123:mytopic'

subscription = conn.smn.create_subscription(topic=topic, **attrs)
print(subscription)

Delete Subscription

This interface is used to delete a SMN subscription instance by id or an instance of class Subscription.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


subscription = 'subscription_urn'
conn.smn.delete_subscription(subscription)

Template

Message templates contain fixed and changeable content and can be used to send messages quickly. When you publish a message using a template, you can specify values for variables in the template. Message templates are grouped by template name. You can create templates for different protocols using the same template name. You must specify the default protocol in any template name, or the system will not allow you to publish messages using that template name. When sending messages using a template, SMN tries to match different types of subscribers to the template protocols. If there is no template for a specified protocol, SMN will use the default template to send messages to subscribers of that protocol.

List Template

This interface is used to query SMN message templates and to filter the output with query parameters.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


for item in conn.smn.templates():
    print(item)

Get Template

This interface is used to get a SMN message template by ID or an instance of class Template.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


template = 'template_id'
template = conn.smn.get_template(template)
print(template)

Find Template

This interface is used to find a SMN message template by name or ID.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


template = 'name_or_id'
template = conn.smn.find_template(name_or_id=template)
print(template)

Create Template

This interface is used to create a SMN template instance with parameters.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


attrs = {
    'name': 'my_template',
    'protocol': 'sms',
    'content': 'my_content'
}
template = conn.smn.create_template(**attrs)
print(template)

Update Template

This interface is used to update a SMN message template instance with parameters.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


template = 'name_or_id'
attrs = {
    'content': 'my_new content'
}
template = conn.smn.find_template(name_or_id=template)
template = conn.smn.update_template(template, **attrs)
print(template)

Delete Template

This interface is used to delete a SMN message template instance by id or an instance of class Template.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


template = 'name_or_id'
template = conn.smn.find_template(name_or_id=template)
conn.smn.delete_template(template)

Message Publishing

Use the message structure to publish a message to the topic. After the message ID is returned, the message has been saved and is to be pushed to the subscribers of the topic. This API allows you to send different message content to different types of subscribers.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


attrs = {
    'subject': 'my_message_subject',
    'message_structure': '{"default":"test v2 default", "email":"abc"}',
    'message_template_name': 'template_name',
    'message': 'my_message',
    'endpoint': '+49123123456789',
    'time_to_live': '3600'
}
response = conn.smn.publish_message(**attrs)
print(response)

SMS Publishing

Send a transactional SMS message to a specified phone number, usually used for verification code or notification.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')


attrs = {
    'endpoint': '+49123123456789',
    'message': 'test message'
}
response = conn.smn.send_sms(**attrs)
print(response)