payload: dict = kwargs['payload'] print(payload) raise Exception("I'm just failing as I'm told ..") # Use pika connection params to set connection details credentials = pika.PlainCredentials('amqp', 'amqp') connParams = pika.ConnectionParameters(host='localhost', port=5672, virtual_host='/', credentials=credentials) # Create a PikaBusSetup instance with a listener queue and your own PikaErrorHandler definition. pikaErrorHandler = PikaErrorHandler(errorQueue='error', maxRetries=1) pikaBusSetup = PikaBusSetup(connParams, defaultListenerQueue='myFailingQueue', pikaErrorHandler=pikaErrorHandler) pikaBusSetup.AddMessageHandler(failingMessageHandlerMethod) # Start consuming messages from the queue. pikaBusSetup.StartConsumers() # Create a temporary bus to subscribe on topics and send, defer or publish messages. bus = pikaBusSetup.CreateBus() payload = {'hello': 'world!', 'reply': True} # To send a message means sending a message explicitly to one receiver. # In this case the message will keep failing and end up in an dead-letter queue called `error`. # Locate the failed message in the `error` queue at the RabbitMq admin portal on http://localhost:15672 (user=amqp, password=amqp) bus.Send(payload=payload, queue='myFailingQueue')
import pika from PikaBus.PikaBusSetup import PikaBusSetup # Use pika connection params to set connection details credentials = pika.PlainCredentials('amqp', 'amqp') connParams = pika.ConnectionParameters( host='localhost', port=5672, virtual_host='/', credentials=credentials) # Create a PikaBusSetup instance without a listener queue pikaBusSetup = PikaBusSetup(connParams) # Create a temporary bus to publish messages. bus = pikaBusSetup.CreateBus() payload = {'hello': 'world!', 'reply': False} # To publish a message means publishing a message on a topic received by any subscribers of the topic. bus.Publish(payload=payload, topic='myTopic')
if payload['reply']: payload['reply'] = False bus.Reply(payload=payload) # Use pika connection params to set connection details credentials = pika.PlainCredentials('amqp', 'amqp') connParams = pika.ConnectionParameters( host='localhost', port=5672, virtual_host='/', credentials=credentials) # Create a PikaBusSetup instance with a listener queue, and add the message handler method. pikaBusSetup = PikaBusSetup(connParams, defaultListenerQueue='myQueue', defaultSubscriptions='myTopic') pikaBusSetup.AddMessageHandler(MessageHandlerMethod) # Start consuming messages from the queue. pikaBusSetup.StartConsumers() # Create a temporary bus to subscribe on topics and send, defer or publish messages. bus = pikaBusSetup.CreateBus() bus.Subscribe('myTopic') payload = {'hello': 'world!', 'reply': True} # To send a message means sending a message explicitly to one receiver. bus.Send(payload=payload, queue='myQueue') # To defer a message means sending a message explicitly to one receiver with some delay before it is processed.