Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test 1 #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import pika
from producer_interface import mqProducerInterface

class mqProducer(mqProducerInterface):
def __init__(self, routing_key: str, exchange_name: str) -> None:
# Save parameters to class variables
self.routing_key = routing_key
self.exchange_name = exchange_name
# Call setupRMQConnection
self.setupRMQConnection()
pass

def setupRMQConnection(self) -> None:
# Set-up Connection to RabbitMQ service
self.con_params = pika.URLParameters(os.environ["AMQP_URL"])
self.connection = pika.BlockingConnection(parameters=self.con_params)

# Establish Channel
self.channel = self.connection.channel()

# Create the exchange if not already present
self.exchange = self.channel.exchange_declare(exchange="Exchange Name")
pass

def publishOrder(self, message: str) -> None:
# Basic Publish to Exchange
self.channel.basic_publish(
self.exchange,
self.routing_key,
body=message)

# Close Channel
self.channel.close()
# Close Connection
self.connection.close()
pass