class_docstr: Pika-based event broker for publishing messages to RabbitMQ.
docstr: Initialise RabbitMQ event broker.
  
  Args:
      host: Pika host.
      username: Username for authentication with Pika host.
      password: Password for authentication with Pika host.
      port: port of the Pika host.
      queues: Pika queues to declare and publish to.
      should_keep_unpublished_messages: Whether or not the event broker should
          maintain a queue of unpublished messages to be published later in
          case of errors.
      raise_on_failure: Whether to raise an exception if publishing fails. If
          `False`, keep retrying.
      event_loop: The event loop which will be used to run `async` functions. If
          `None` `asyncio.get_event_loop()` is used to get a loop.
      connection_attempts: Number of attempts for connecting to RabbitMQ before
          an exception is thrown.
      retry_delay_in_seconds: Time in seconds between connection attempts.
      exchange_name: Exchange name to which the queues binds to.
          If nothing is mentioned then the default exchange name would be used.
docstr_tok: ["Initialise","RabbitMQ","event","broker",".","Args",":","host",":","Pika","host",".","username",":","Username","for","authentication","with","Pika","host",".","password",":","Password","for","authentication","with","Pika","host",".","port",":","port","of","the","Pika","host",".","queues",":","Pika","queues","to","declare","and","publish","to",".","should_keep_unpublished_messages",":","Whether","or","not","the","event","broker","should","maintain","a","queue","of","unpublished","messages","to","be","published","later","in","case","of","errors",".","raise_on_failure",":","Whether","to","raise","an","exception","if","publishing","fails",".","If","`","False","`",",","keep","retrying",".","event_loop",":","The","event","loop","which","will","be","used","to","run","`","async","`","functions",".","If","`","None","`","`","asyncio.get_event_loop","(",")","`","is","used","to","get","a","loop",".","connection_attempts",":","Number","of","attempts","for","connecting","to","RabbitMQ","before","an","exception","is","thrown",".","retry_delay_in_seconds",":","Time","in","seconds","between","connection","attempts",".","exchange_name",":","Exchange","name","to","which","the","queues","binds","to",".","If","nothing","is","mentioned","then","the","default","exchange","name","would","be","used","."]
code: def __init__(
      self,
      host: Text,
      username: Text,
      password: Text,
      port: Union[int, Text] = 5672,
      queues: Union[List[Text], Tuple[Text, ...], Text, None] = None,
      should_keep_unpublished_messages: bool = True,
      raise_on_failure: bool = False,
      event_loop: Optional[AbstractEventLoop] = None,
      connection_attempts: int = 20,
      retry_delay_in_seconds: float = 5,
      exchange_name: Text = RABBITMQ_EXCHANGE,
      **kwargs: Any,
  ):
      """Initialise RabbitMQ event broker.
  
      Args:
          host: Pika host.
          username: Username for authentication with Pika host.
          password: Password for authentication with Pika host.
          port: port of the Pika host.
          queues: Pika queues to declare and publish to.
          should_keep_unpublished_messages: Whether or not the event broker should
              maintain a queue of unpublished messages to be published later in
              case of errors.
          raise_on_failure: Whether to raise an exception if publishing fails. If
              `False`, keep retrying.
          event_loop: The event loop which will be used to run `async` functions. If
              `None` `asyncio.get_event_loop()` is used to get a loop.
          connection_attempts: Number of attempts for connecting to RabbitMQ before
              an exception is thrown.
          retry_delay_in_seconds: Time in seconds between connection attempts.
          exchange_name: Exchange name to which the queues binds to.
              If nothing is mentioned then the default exchange name would be used.
      """
      super().__init__()
  
      self.host = host
      self.username = username
      self.password = password
  
      try:
          self.port = int(port)
      except ValueError as e:
          raise RasaException(
              "Port could not be converted to integer."
          ) from e
  
      self.queues = self._get_queues_from_args(queues)
      self.raise_on_failure = raise_on_failure
      self._connection_attempts = connection_attempts
      self._retry_delay_in_seconds = retry_delay_in_seconds
      self.exchange_name = exchange_name
  
      # Unpublished messages which hopefully will be published later 🤞
      self._unpublished_events: Deque[Dict[Text, Any]] = deque()
      self.should_keep_unpublished_messages = (
          should_keep_unpublished_messages
      )
  
      self._loop = event_loop or asyncio.get_event_loop()
      self._background_tasks: Set[asyncio.Task] = set()
  
      self._connection: Optional[
          aio_pika.abc.AbstractRobustConnection
      ] = None
      self._exchange: Optional[aio_pika.RobustExchange] = None
  
imports: import asyncio
  import json
  import logging
  import structlog
  import os
  import ssl
  from asyncio import AbstractEventLoop
  from collections import deque
  from typing import Deque, Dict, Optional, Text, Union, Any, List, Set, Tuple, cast
  from urllib.parse import urlparse
  import aio_pika
  from rasa.shared.exceptions import RasaException
  from rasa.shared.constants import DOCS_URL_PIKA_EVENT_BROKER
  from rasa.core.brokers.broker import EventBroker
  import rasa.shared.utils.io
  from rasa.utils.endpoints import EndpointConfig
  from rasa.shared.utils.io import DEFAULT_ENCODING
  import rasa.shared.utils.common
label_desc: Use image node_id 1 to create a new PikaEventBroker object from inherited base classes: EventBroker with example: obj = PikaEventBroker(host, username, password, port, queues, should_keep_unpublished_messages, raise_on_failure, event_loop, connection_attempts, retry_delay_in_seconds, exchange_name)