mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-05-19 12:25:13 +02:00
Messaging fabric plugins (#592)
* Plugin architecture for messaging fabric * Schemas use a technology neutral expression * Schemas strictness has uncovered some incorrect schema use which is fixed
This commit is contained in:
parent
1865b3f3c8
commit
34eb083836
100 changed files with 2342 additions and 828 deletions
|
|
@ -7,6 +7,7 @@ import time
|
|||
from pulsar.schema import JsonSchema
|
||||
|
||||
from .. exceptions import *
|
||||
from ..base.pubsub import get_pubsub
|
||||
|
||||
# Default timeout for a request/response. In seconds.
|
||||
DEFAULT_TIMEOUT=300
|
||||
|
|
@ -39,30 +40,25 @@ class BaseClient:
|
|||
if subscriber == None:
|
||||
subscriber = str(uuid.uuid4())
|
||||
|
||||
if pulsar_api_key:
|
||||
auth = pulsar.AuthenticationToken(pulsar_api_key)
|
||||
self.client = pulsar.Client(
|
||||
pulsar_host,
|
||||
logger=pulsar.ConsoleLogger(log_level),
|
||||
authentication=auth,
|
||||
listener=listener,
|
||||
)
|
||||
else:
|
||||
self.client = pulsar.Client(
|
||||
pulsar_host,
|
||||
logger=pulsar.ConsoleLogger(log_level),
|
||||
listener_name=listener,
|
||||
)
|
||||
# Create backend using factory
|
||||
self.backend = get_pubsub(
|
||||
pulsar_host=pulsar_host,
|
||||
pulsar_api_key=pulsar_api_key,
|
||||
pulsar_listener=listener,
|
||||
pubsub_backend='pulsar'
|
||||
)
|
||||
|
||||
self.producer = self.client.create_producer(
|
||||
self.producer = self.backend.create_producer(
|
||||
topic=input_queue,
|
||||
schema=JsonSchema(input_schema),
|
||||
schema=input_schema,
|
||||
chunking_enabled=True,
|
||||
)
|
||||
|
||||
self.consumer = self.client.subscribe(
|
||||
output_queue, subscriber,
|
||||
schema=JsonSchema(output_schema),
|
||||
self.consumer = self.backend.create_consumer(
|
||||
topic=output_queue,
|
||||
subscription=subscriber,
|
||||
schema=output_schema,
|
||||
consumer_type='shared',
|
||||
)
|
||||
|
||||
self.input_schema = input_schema
|
||||
|
|
@ -136,10 +132,11 @@ class BaseClient:
|
|||
|
||||
if hasattr(self, "consumer"):
|
||||
self.consumer.close()
|
||||
|
||||
|
||||
if hasattr(self, "producer"):
|
||||
self.producer.flush()
|
||||
self.producer.close()
|
||||
|
||||
self.client.close()
|
||||
|
||||
if hasattr(self, "backend"):
|
||||
self.backend.close()
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,6 @@ class ConfigClient(BaseClient):
|
|||
def get(self, keys, timeout=300):
|
||||
|
||||
resp = self.call(
|
||||
id=id,
|
||||
operation="get",
|
||||
keys=[
|
||||
ConfigKey(
|
||||
|
|
@ -88,7 +87,6 @@ class ConfigClient(BaseClient):
|
|||
def list(self, type, timeout=300):
|
||||
|
||||
resp = self.call(
|
||||
id=id,
|
||||
operation="list",
|
||||
type=type,
|
||||
timeout=timeout
|
||||
|
|
@ -99,7 +97,6 @@ class ConfigClient(BaseClient):
|
|||
def getvalues(self, type, timeout=300):
|
||||
|
||||
resp = self.call(
|
||||
id=id,
|
||||
operation="getvalues",
|
||||
type=type,
|
||||
timeout=timeout
|
||||
|
|
@ -117,7 +114,6 @@ class ConfigClient(BaseClient):
|
|||
def delete(self, keys, timeout=300):
|
||||
|
||||
resp = self.call(
|
||||
id=id,
|
||||
operation="delete",
|
||||
keys=[
|
||||
ConfigKey(
|
||||
|
|
@ -134,7 +130,6 @@ class ConfigClient(BaseClient):
|
|||
def put(self, values, timeout=300):
|
||||
|
||||
resp = self.call(
|
||||
id=id,
|
||||
operation="put",
|
||||
values=[
|
||||
ConfigValue(
|
||||
|
|
@ -152,7 +147,6 @@ class ConfigClient(BaseClient):
|
|||
def config(self, timeout=300):
|
||||
|
||||
resp = self.call(
|
||||
id=id,
|
||||
operation="config",
|
||||
timeout=timeout
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue