Exemplo n.º 1
0
def zaqar_to_proton(message):
    """Convert a message retrieved from storage to a Proton message"""
    msg = Message()

    msg.ttl = message.get('ttl')
    msg.body = message.get('body')

    # NOTE(vkmc) This won't work for now - there is no 'amqp10' field yet
    if message.get('amqp10'):
        msg.priority = message.get('amqp10').get('priority')
        msg.first_acquirer = message.get('amqp10').get('first_acquirer')
        msg.delivery_count = message.get('amqp10').get('delivery_count')
        msg.id = message.get('amqp10').get('id'),
        msg.user_id = message.get('amqp10').get('user_id')
        msg.address = message.get('amqp10').get('address')
        msg.subject = message.get('amqp10').get('subject')
        msg.reply_to = message.get('amqp10').get('reply_to')
        msg.correlation_id = message.get('amqp10').get('correlation_id')
        msg.content_type = message.get('amqp10').get('content_type')
        msg.content_encoding = message.get('amqp10').get('content_encoding')
        msg.expiry_time = message.get('amqp10').get('expiry_time')
        msg.creation_time = message.get('amqp10').get('creation_time'),
        msg.group_id = message.get('amqp10').get('group_id')
        msg.group_sequence = message.get('amqp10').get('group_sequence')
        msg.reply_to_group_id = message.get('amqp10').get('reply_to_group_id')
        msg.format = message.get('amqp10').get('format')

    return msg
Exemplo n.º 2
0
    def departures_today_handler(self,
                                 icao24: str,
                                 context: Optional[Any] = None) -> Message:
        departures = self._get_departures_today(icao24)

        message = Message()
        message.content_type = 'application/json'
        message.body = json.dumps(departures)

        return message
Exemplo n.º 3
0
    def arrivals_today_handler(self,
                               icao24: str,
                               context: Optional[Any] = None) -> Message:
        arrivals = self._get_arrivals_today(icao24)

        message = Message()
        message.content_type = 'application/json'
        message.body = json.dumps(arrivals)

        return message
Exemplo n.º 4
0
def create_message(body: Union[str, bytes, dict, list],
                   properties: Optional[dict] = None,
                   priority: Priority = Priority.normal) -> Message:
    """Utility method to create message with common attributes.

    Args:
        body: Message body.
        properties: Message properties.
        priority: Message priority.

    Returns:
        Message: Created message.
    """
    message = Message(body=body,
                      durable=True,
                      priority=priority.value,
                      properties=properties or {})
    if isinstance(body, bytes):
        message.content_type = 'application/octet-stream'
    else:
        message.content_type = None

    return message
Exemplo n.º 5
0
 def on_sendable(self, event):
     if not self.sent:
         msg = Message()
         msg.address = self.address
         msg.id = '123455'
         msg.user_id = BINARY('testuser')
         msg.subject = 'test-subject'
         msg.content_type = 'text/html; charset=utf-8'
         msg.correlation_id = 89
         msg.creation_time = 1487772623.883
         msg.group_id = "group1"
         msg.reply_to = 'hello_world'
         msg.content_encoding = 'gzip, deflate'
         msg.reply_to_group_id = "group0"
         application_properties = dict()
         application_properties['app-property'] = [10, 20, 30]
         application_properties['some-other'] = symbol("O_one")
         msg.properties = application_properties
         msg.body = u"Hello World!"
         event.sender.send(msg)
         self.sent = True
 def on_sendable(self, event):
     if not self.sent:
         msg = Message()
         msg.address = self.address
         msg.id = '123455'
         msg.user_id = 'testuser'
         msg.subject = 'test-subject'
         msg.content_type = 'text/html; charset=utf-8'
         msg.correlation_id = 89
         msg.creation_time = 1487772623.883
         msg.group_id = "group1"
         msg.reply_to = 'hello_world'
         msg.content_encoding = 'gzip, deflate'
         msg.reply_to_group_id = "group0"
         application_properties = dict()
         application_properties['app-property'] = [10, 20, 30]
         application_properties['some-other'] = symbol("O_one")
         msg.properties = application_properties
         msg.body = u"Hello World!"
         event.sender.send(msg)
         self.sent = True
Exemplo n.º 7
0
Arquivo: app.py Projeto: ssorj/meteo
    def send_update(self):
        if self.sender is None or self.sender.credit < 1:
            return

        print("PYTHON-AMQP: Sending update")

        update = {
            "station_id": station_id,
            "time": round(time.time() * 1000),
            "latitude": 3.459718,
            "longitude": -76.439529,
            "temperature": 20.518,
            "humidity": None,
            "pressure": None,
        }

        message = Message()
        message.content_type = "application/json"
        message.inferred = False
        message.body = json.dumps(update).encode("utf-8")

        self.sender.send(message)