def publish_with_delay(self, event_name, network, delay=0, data=None, id=None, topic_prefix=None): message_header = {'x-delay': str(delay)} now = self.clock.now() event = events.Event(event_name, network, data, self.clock.timestamp(now), id, topic_prefix, timestamp_str=str(now)) self.rabbitmq_client.exchange_declare( exchange=self.exchange, type=X_DELAYED, durable=True, arguments={'x-delayed-type': 'topic'}) self.rabbitmq_client.publish(exchange=self.exchange, routing_key=event.topic, message=event, headers=message_header)
def publish(self, event_name, network, data=None, id=None, topic_prefix=None): now = self.clock.now() event = events.Event(event_name, network, data, self.clock.timestamp(now), id, topic_prefix, timestamp_str=str(now)) self.publish_event_object(event)
def publish_with_ttl(self, event_name, network, ttl, data=None, id=None, topic_prefix=None): message_header = {'expiration': str(ttl)} now = self.clock.now() event = events.Event(event_name, network, data, self.clock.timestamp(now), id, topic_prefix, timestamp_str=str(now)) self.rabbitmq_client.exchange_declare(exchange=self.exchange, type=TOPIC, durable=True) self.rabbitmq_client.publish(exchange=self.exchange, routing_key=event.topic, message=event, headers=message_header)
def felix_event_builder(raw_event): return events.Event(**raw_event)
# -*- coding: utf-8 -*- from expects import expect, equal from infrabbitmq import events PREFIX = 'irrelevant-prefix' NETWORK = 'irrelevant-network' NAME = 'irrelevant-name' with description('Event test'): with context('when creating an event'): with context('when specifing a prefix'): with it('returns the topic with the specified prefix'): event = events.Event(NAME, NETWORK, 'data', topic_prefix=PREFIX) expected_topic = '{}.{}.{}'.format(NETWORK, PREFIX, NAME) expect(event.topic).to(equal(expected_topic)) with context('when NOT specifing a prefix'): with it('returns the topic without prefix'): event = events.Event(NAME, NETWORK, 'data') expected_topic = '{}.{}'.format(NETWORK, NAME) expect(event.topic).to(equal(expected_topic))