Metadata-Version: 2.1
Name: rest-solace
Version: 0.0.1
Summary: REST based library for Solace Message Broker. Publish, Consume, & Manage!!
Author-email: Skyler Guha <skylerguha@gmail.com>
Maintainer-email: Skyler Guha <skylerguha@gmail.com>
License: apache 2.0
Project-URL: homepage, https://github.com/skyler-guha/rest-solace
Project-URL: documentation, https://github.com/skyler-guha/rest-solace
Project-URL: repository, https://github.com/skyler-guha/rest-solace
Keywords: solace,rest,REST API,rest-solace,rest_solace,rest solace,python,pythonic
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Intended Audience :: Developers
Requires-Python: >=3.8
Description-Content-Type: text/x-rst
License-File: LICENSE.txt
License-File: NOTICE.txt
Requires-Dist: requests >=2.30.0
Requires-Dist: http >=0.02
Requires-Dist: functools
Requires-Dist: datetime
Requires-Dist: typing
Requires-Dist: queue
Requires-Dist: threading
Requires-Dist: json
Requires-Dist: urllib


rest-solace
===============

rest-solace is a rest based library for Solace Message Broker that allows you to Publish, Consume, & Manage!!

Check it out at PYPI: `PYPI page for the project <https://pypi.org/project/rest-solace/>`_.

Note: 
	| Right now the focus of this library is on the 'messaging' mode for solace message VPNs.
	| In the future I plan to add better support for 'gateway' mode as well.

|

Sending messages to broker:
----------------------------

.. code-block:: python

	from rest_solace import MessagingPublisher

	publisher_obj = MessagingPublisher(user_name= "admin", 
									   password=" admin", 
                                       host= BROKER_IP, 
									   REST_VPNport= VPN_PORT #For 'default' VPN it is 9000
									   )

	#Publish directly to a queue
	publish_obj.publishToQueueEndpoint(queue_name= "my_queue", 
									   message= "hello world!!",
									   delivery_mode= "direct")
	
	#Publish for a given topic string
	publish_obj.publishForTopic(topic_string= "test_topic", 
								message= "hello world!!",
								delivery_mode= "direct")


	#Publish directly to a queue and wait for a reply from a consumer
	response = publish_obj.publishToQueueEndpoint(queue_name= "my_queue", 
												  message= "hello world!!",
												  delivery_mode= "persistent",
												  time_to_live= 10000)
	print(response)

	#Publish for a given topic string and wait for a reply from a consumer
	response = publish_obj.publishForTopic(topic_string= "test_topic", 
										   message= "hello world!!",
										   delivery_mode= "direct")
	print(response)

|

Receiving messages and sending back a response 
-----------------------------------------------
(You can use your own REST server too. The one included with this library is only for simple uses and testing)

.. code-block:: python

	from rest_solace import Consumer

	consumer_obj = Consumer()

	#Receive a single message and get the value returned to you.
	incoming_message = consumer_obj.startConsumer(host= CONSUMER_HOST, 
												  port= CONSUMER_PORT, 
                                				  auto_stop= True #Required for single message mode
												  )
	print(incoming_message)


	#Keep receiving messages and handle them through a callback function

	def return_uppercase(event:dict, kill_function):
    """Convert request message string to upper case to return as response.
	Stops the consumer server if message is "kill".

    Args:
        event (dict): contains info about the received request.
		kill_function (function): stops the consumer server if you run it.
    Returns:
        str: Returns the incoming message to the publisher in uppercase
    """
    byte_string_content= event["content"][1:-1]
    regular_string_content= byte_string_content.decode("utf-8")
	uppercase_response= str.upper( regular_string_content ) 
	
	if regular_string_content == "kill":
		kill_function()
    
    return uppercase_response

	#You can run this function on a septate thread if you want.
	consumer_obj.startConsumer(host= CONSUMER_HOST, 
							   port= CONSUMER_PORT,
                               callback_function= return_uppercase, 
							   log= True)
    
|

Setting up a message VPN for message broking (in messaging mode)
-----------------------------------------------------------------
(This is a bit advance but the library includes lots of utility functions to make initial setup easy)

.. code-block:: python

	from rest_solace import Manager

	manager = Manager(user_name= admin, 
                      password= admin, 
                      host= BROKER_IP, 
                      SEMP_port= SEMP_PORT) #Default rest management port is 8080

	
	#Creating a custom message VPN 
	#(automatically applies required VPN configuration for rest based communication).
	manager.create_message_vpn(msgVpnName= NEW_VPN_NAME,
                               serviceRestIncomingPlainTextListenPort= NEW_VPN_PORT,
							   serviceRestMode= "messaging" #auto configuration will be influenced by this parameter.
							   )

	
	#Setting up your Message VPN for rest based communication
	#(For VPN that is in messaging mode)
	manager.auto_rest_messaging_setup_utility(msgVpnName= NEW_VPN_NAME, #Existing message VPN

											  queueName= 'my_queue',  #Creates a new queue

											  subscriptionTopic=None,  #The topic the queue should subscribe to

                                              restDeliveryPointName='myRDP',  #New RDP to handle incoming messages

											  restConsumerName='myConsumer',	#A name for your consumer

                                              remoteHost= CONSUMER_HOST, 
											  remotePort= CONSUMER_PORT)

	


	
