def _create_from_endpoint_config( endpoint_config: Optional[EndpointConfig], ) -> Optional["EventBroker"]: """Instantiate an event broker based on its configuration.""" if endpoint_config is None: broker = None elif endpoint_config.type is None or endpoint_config.type.lower() == "pika": from rasa.core.brokers.pika import PikaEventBroker # default broker if no type is set broker = PikaEventBroker.from_endpoint_config(endpoint_config) elif endpoint_config.type.lower() == "sql": from rasa.core.brokers.sql import SQLEventBroker broker = SQLEventBroker.from_endpoint_config(endpoint_config) elif endpoint_config.type.lower() == "file": from rasa.core.brokers.file import FileEventBroker broker = FileEventBroker.from_endpoint_config(endpoint_config) elif endpoint_config.type.lower() == "kafka": from rasa.core.brokers.kafka import KafkaEventBroker broker = KafkaEventBroker.from_endpoint_config(endpoint_config) else: broker = _load_from_module_string(endpoint_config) if broker: logger.debug(f"Instantiated event broker to '{broker.__class__.__name__}'.") return broker
def __init__( self, path_context: PathContext, agent: Agent = None, ): ''' agent manager Args: model: Path to model archive. endpoints: Path to endpoints file. credentials: Path to channel credentials file. ''' self.path_context = path_context endpoints_path = self.path_context.endpoints_file_path credentials_path = self.path_context.credentials_file_path self.agent = agent if agent else None # broker tracker # read file if have endpoints file otherwise use default setting if os.path.exists(endpoints_path): # load endpoints self._load_endpoints(endpoints=endpoints_path) else: # create event broker event_broker = FileEventBroker() # TODO 修改这里的broker,file格式的不太适合生产 # create tracker store from config.settings import REDIS_SETTING self.tracker_store = TrackerStore(**REDIS_SETTING, event_broker=event_broker)
def from_endpoint_config( cls, broker_config: EndpointConfig, event_loop: Optional[AbstractEventLoop] = None, ) -> "EventBroker": return FileEventBroker()