Ejemplo n.º 1
0
 async def send(self, topic: str, key: Optional[bytes],
                value: Optional[bytes],
                partition: Optional[int],
                timestamp: Optional[float],
                headers: Optional[HeadersArg],
                *,
                transactional_id: str = None) -> Awaitable[RecordMetadata]:
     """Schedule message to be transmitted by producer."""
     producer = self._ensure_producer()
     if headers is not None:
         if isinstance(headers, Mapping):
             headers = list(headers.items())
     self._send_on_produce_message(
         key=key, value=value,
         partition=partition,
         timestamp=timestamp,
         headers=headers,
     )
     if headers is not None and not self.allow_headers:
         headers = None
     timestamp_ms = int(timestamp * 1000.0) if timestamp else timestamp
     try:
         return cast(Awaitable[RecordMetadata], await producer.send(
             topic, value,
             key=key,
             partition=partition,
             timestamp_ms=timestamp_ms,
             headers=headers,
             transactional_id=transactional_id,
         ))
     except KafkaError as exc:
         raise ProducerSendError(f'Error while sending: {exc!r}') from exc
Ejemplo n.º 2
0
 async def send(self,
                topic: str,
                key: Optional[bytes],
                value: Optional[bytes],
                partition: Optional[int],
                timestamp: Optional[float],
                headers: Optional[HeadersArg],
                *,
                transactional_id: str = None) -> Awaitable[RecordMetadata]:
     """Send message for future delivery."""
     fut = ProducerProduceFuture(loop=self.loop)
     self._quick_produce(
         topic,
         value,
         key,
         partition,
         timestamp=int(timestamp * 1000) if timestamp else timestamp,
         on_delivery=fut.set_from_on_delivery,
     )
     return cast(Awaitable[RecordMetadata], fut)
     try:
         return cast(
             Awaitable[RecordMetadata],
             await self._producer.send(topic,
                                       value,
                                       key=key,
                                       partition=partition))
     except KafkaException as exc:
         raise ProducerSendError(f'Error while sending: {exc!r}') from exc
Ejemplo n.º 3
0
 async def send(self,
                topic: str,
                key: Optional[bytes],
                value: Optional[bytes],
                partition: Optional[int],
                timestamp: Optional[float],
                headers: Optional[HeadersArg],
                *,
                transactional_id: str = None) -> Awaitable[RecordMetadata]:
     producer = self._ensure_producer()
     if headers is not None and isinstance(headers, Mapping):
         headers = list(headers.items())
     try:
         timestamp_ms = timestamp * 1000.0 if timestamp else timestamp
         return cast(
             Awaitable[RecordMetadata], await producer.send(
                 topic,
                 value,
                 key=key,
                 partition=partition,
                 timestamp_ms=timestamp_ms,
                 headers=headers,
                 transactional_id=transactional_id,
             ))
     except KafkaError as exc:
         raise ProducerSendError(f'Error while sending: {exc!r}') from exc
Ejemplo n.º 4
0
 async def send(self, topic: str, key: Optional[bytes],
                value: Optional[bytes],
                partition: Optional[int]) -> Awaitable[RecordMetadata]:
     try:
         return cast(Awaitable[RecordMetadata], await self._producer.send(
             topic, value, key=key, partition=partition))
     except KafkaError as exc:
         raise ProducerSendError(f'Error while sending: {exc!r}') from exc
Ejemplo n.º 5
0
 async def send(self, topic: str, key: Optional[bytes],
                value: Optional[bytes],
                partition: Optional[int],
                timestamp: Optional[float]) -> Awaitable[RecordMetadata]:
     try:
         timestamp_ms = timestamp * 1000.0 if timestamp else timestamp
         return cast(Awaitable[RecordMetadata], await self._producer.send(
             topic, value,
             key=key,
             partition=partition,
             timestamp_ms=timestamp_ms,
         ))
     except KafkaError as exc:
         raise ProducerSendError(f'Error while sending: {exc!r}') from exc