aissemble-foundation-messaging-python


Nameaissemble-foundation-messaging-python JSON
Version 1.9.2 PyPI version JSON
download
home_pageNone
SummaryDefines a root level messaging architecture in python
upload_time2024-09-26 20:39:17
maintainerNone
docs_urlNone
authoraiSSEMBLE Baseline Community
requires_python<4,>=3.11.4
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## aiSSMEBLE&trade; Foundation Python Messaging Client (UNDER CONSTRUCTION)

[![PyPI](https://img.shields.io/pypi/v/aissemble-foundation-messaging-python?logo=python&logoColor=gold)](https://pypi.org/project/aissemble-foundation-messaging-python/)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/aissemble-foundation-messaging-python?logo=python&logoColor=gold)
![PyPI - Wheel](https://img.shields.io/pypi/wheel/aissemble-foundation-messaging-python?logo=python&logoColor=gold)

# Overview
aiSSEMBLE&trade;'s python messaging module provides an interface through which python pipelines can leverage messaging's
features. This is done through the MessagingClient class, the details of which are discussed below, along with
examples of its use.

# Subscribing
The messaging client can pass along a subscription request to the service to subscribe to a given topic. The message client can start receiving messages after subscription. However, any messages before subscription will be ignored. To do this, you will need to tell the service which topic you want to subscribe to, provide a callback function if you would like to execute one, and an acknowledgement strategy for handling messages on the topic.

```python
def my_pipeline_function()
client = MessagingClient()
ack_strategy = AckStrategy.<STRATEGY>
client.subscribe("topic_name", my_callback_func(), ack_strategy)
```

# Sending
The messaging client can send a message to a given topic name through the service and will receive back a future object to handle that messages receipt. To do this, you can simply provide a topic name and a message object containing the text string for your message, like the following example.

```python
c = MessagingClient()
message = Message()
message.set_payload("test message")
result = c.queueForSend("TopicA", message)
```

# Receiving
The message client can receive a message to a given topic name through the service after subscribe to the topic. However, any messages to the given topic before subscription is made will be ignored.

To do this, you can define a Callback function and subscribe to the topic with the Callback function created, like the following example:

Note: the client can must ack or nack the message received. If there are any exception thrown during the process time, the exception will be handled by the service and the message will be nacked.
```python
from aissemble_messaging import ProcessMessageError, MessagingClient, AckStrategy, Message, Callback
import threading

def receive_message(msg: Message, topic):
    message_received = msg.get_payload()
    print("Received message from topic: {}, message: {}".format(topic, message_received))
    
    # to nack a message, return msg.nack(reason)
    # ex:
    if "nacked" in message_received :
        return msg.nack("receiver nacks the message: " + message_received)
    
    # when raise an Exception for any issue, message will be nacked
    # ex:
    if "problem" in message_received:
        raise Exception("error while processing message: " + message_received)

    # to ack a message, return msg.ack()
    return msg.ack()

def demo_topic_callback(msg: Message):
    receive_message(msg, "demoTopic")
    
def subscribe_to_topic(consumer, callback_func):
    consumer.subscribe("demoTopic", callback_func, AckStrategy.MANUAL)
    is_subscribed = consumer.isTopicSubscribed("demoTopic")
    while is_subscribed:
        pass


# Create MessageClient with default and the messaging configration
client = MessagingClient(properties_location = os.path.join("microprofile-config.properties"))

sb_thread = threading.Thread(target=subscribe_to_topic,args=[client, Callback(demo_topic_callback)])
sb_thread.start()
```

# Misc.
The testing strategy for the client's integration tests is to run the messaging service's jar through py4j's launch_gateway() function, and then interact with it through the MessagingClient class. In addition to running the jar, the launch_gateway() function has some quality of life features for testing. In order to include logging from the jvm in the python test output, add the following parameters to the function, and run the behave tests with the --no-capture flag.

```python
redirect_stdout=sys.stdout,
redirect_stderr=sys.stdout
```

Please see the [aiSSEMBLE Messaging documentation](https://boozallen.github.io/aissemble/aissemble/current/messaging-details.html)
for additional general information.
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "aissemble-foundation-messaging-python",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.11.4",
    "maintainer_email": null,
    "keywords": null,
    "author": "aiSSEMBLE Baseline Community",
    "author_email": "aissemble@bah.com",
    "download_url": "https://files.pythonhosted.org/packages/5b/ae/5e015124a20b07bab1b068f0a6f24e637156381729b1bd00d8280c8ec7f3/aissemble_foundation_messaging_python-1.9.2.tar.gz",
    "platform": null,
    "description": "## aiSSMEBLE&trade; Foundation Python Messaging Client (UNDER CONSTRUCTION)\n\n[![PyPI](https://img.shields.io/pypi/v/aissemble-foundation-messaging-python?logo=python&logoColor=gold)](https://pypi.org/project/aissemble-foundation-messaging-python/)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/aissemble-foundation-messaging-python?logo=python&logoColor=gold)\n![PyPI - Wheel](https://img.shields.io/pypi/wheel/aissemble-foundation-messaging-python?logo=python&logoColor=gold)\n\n# Overview\naiSSEMBLE&trade;'s python messaging module provides an interface through which python pipelines can leverage messaging's\nfeatures. This is done through the MessagingClient class, the details of which are discussed below, along with\nexamples of its use.\n\n# Subscribing\nThe messaging client can pass along a subscription request to the service to subscribe to a given topic. The message client can start receiving messages after subscription. However, any messages before subscription will be ignored. To do this, you will need to tell the service which topic you want to subscribe to, provide a callback function if you would like to execute one, and an acknowledgement strategy for handling messages on the topic.\n\n```python\ndef my_pipeline_function()\nclient = MessagingClient()\nack_strategy = AckStrategy.<STRATEGY>\nclient.subscribe(\"topic_name\", my_callback_func(), ack_strategy)\n```\n\n# Sending\nThe messaging client can send a message to a given topic name through the service and will receive back a future object to handle that messages receipt. To do this, you can simply provide a topic name and a message object containing the text string for your message, like the following example.\n\n```python\nc = MessagingClient()\nmessage = Message()\nmessage.set_payload(\"test message\")\nresult = c.queueForSend(\"TopicA\", message)\n```\n\n# Receiving\nThe message client can receive a message to a given topic name through the service after subscribe to the topic. However, any messages to the given topic before subscription is made will be ignored.\n\nTo do this, you can define a Callback function and subscribe to the topic with the Callback function created, like the following example:\n\nNote: the client can must ack or nack the message received. If there are any exception thrown during the process time, the exception will be handled by the service and the message will be nacked.\n```python\nfrom aissemble_messaging import ProcessMessageError, MessagingClient, AckStrategy, Message, Callback\nimport threading\n\ndef receive_message(msg: Message, topic):\n    message_received = msg.get_payload()\n    print(\"Received message from topic: {}, message: {}\".format(topic, message_received))\n    \n    # to nack a message, return msg.nack(reason)\n    # ex:\n    if \"nacked\" in message_received :\n        return msg.nack(\"receiver nacks the message: \" + message_received)\n    \n    # when raise an Exception for any issue, message will be nacked\n    # ex:\n    if \"problem\" in message_received:\n        raise Exception(\"error while processing message: \" + message_received)\n\n    # to ack a message, return msg.ack()\n    return msg.ack()\n\ndef demo_topic_callback(msg: Message):\n    receive_message(msg, \"demoTopic\")\n    \ndef subscribe_to_topic(consumer, callback_func):\n    consumer.subscribe(\"demoTopic\", callback_func, AckStrategy.MANUAL)\n    is_subscribed = consumer.isTopicSubscribed(\"demoTopic\")\n    while is_subscribed:\n        pass\n\n\n# Create MessageClient with default and the messaging configration\nclient = MessagingClient(properties_location = os.path.join(\"microprofile-config.properties\"))\n\nsb_thread = threading.Thread(target=subscribe_to_topic,args=[client, Callback(demo_topic_callback)])\nsb_thread.start()\n```\n\n# Misc.\nThe testing strategy for the client's integration tests is to run the messaging service's jar through py4j's launch_gateway() function, and then interact with it through the MessagingClient class. In addition to running the jar, the launch_gateway() function has some quality of life features for testing. In order to include logging from the jvm in the python test output, add the following parameters to the function, and run the behave tests with the --no-capture flag.\n\n```python\nredirect_stdout=sys.stdout,\nredirect_stderr=sys.stdout\n```\n\nPlease see the [aiSSEMBLE Messaging documentation](https://boozallen.github.io/aissemble/aissemble/current/messaging-details.html)\nfor additional general information.",
    "bugtrack_url": null,
    "license": null,
    "summary": "Defines a root level messaging architecture in python",
    "version": "1.9.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "24026901cf333b2839818bce12116a021a9ba796cb8664ee859f8b707808aa7b",
                "md5": "5abed0ebfeea0afe045cc654c5a61ea5",
                "sha256": "a99178a058f91c189b9d5523712a5903b56142e4b58ff127273bbcdd5ae37730"
            },
            "downloads": -1,
            "filename": "aissemble_foundation_messaging_python-1.9.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5abed0ebfeea0afe045cc654c5a61ea5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.11.4",
            "size": 78968825,
            "upload_time": "2024-09-26T20:39:12",
            "upload_time_iso_8601": "2024-09-26T20:39:12.287947Z",
            "url": "https://files.pythonhosted.org/packages/24/02/6901cf333b2839818bce12116a021a9ba796cb8664ee859f8b707808aa7b/aissemble_foundation_messaging_python-1.9.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5bae5e015124a20b07bab1b068f0a6f24e637156381729b1bd00d8280c8ec7f3",
                "md5": "c36af658afd0d5e1adbae950ad929ca1",
                "sha256": "6375b8d21ea451b0b1cf9c5ddc64214cf19825a209cc70447fdd18c651a32672"
            },
            "downloads": -1,
            "filename": "aissemble_foundation_messaging_python-1.9.2.tar.gz",
            "has_sig": false,
            "md5_digest": "c36af658afd0d5e1adbae950ad929ca1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.11.4",
            "size": 78916621,
            "upload_time": "2024-09-26T20:39:17",
            "upload_time_iso_8601": "2024-09-26T20:39:17.364157Z",
            "url": "https://files.pythonhosted.org/packages/5b/ae/5e015124a20b07bab1b068f0a6f24e637156381729b1bd00d8280c8ec7f3/aissemble_foundation_messaging_python-1.9.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-26 20:39:17",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "aissemble-foundation-messaging-python"
}
        
Elapsed time: 0.39228s