-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from phenobarbital/dev
New Message Brokers
- Loading branch information
Showing
23 changed files
with
1,180 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from navigator import Application | ||
from navigator.brokers.rabbitmq import RMQConsumer | ||
|
||
|
||
async def rabbit_callback(*args, **kwargs): | ||
# Handle your SQS callback here | ||
print('Received Message:', args, kwargs) | ||
|
||
app = Application( | ||
port=5001 | ||
) | ||
|
||
rmq = RMQConsumer( | ||
callback=rabbit_callback | ||
) | ||
rmq.setup(app) | ||
|
||
if __name__ == '__main__': | ||
try: | ||
app.run() | ||
except KeyboardInterrupt: | ||
print('EXIT FROM APP =========') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from navigator import Application | ||
from navigator.brokers.redis import RedisConsumer | ||
|
||
|
||
async def redis_callback(*args, **kwargs): | ||
# Handle your SQS callback here | ||
print('Received Message:', args, kwargs) | ||
|
||
app = Application( | ||
port=5001 | ||
) | ||
|
||
rmq = RedisConsumer( | ||
callback=redis_callback | ||
) | ||
rmq.setup(app) | ||
|
||
if __name__ == '__main__': | ||
try: | ||
app.run() | ||
except KeyboardInterrupt: | ||
print('EXIT FROM APP =========') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from navigator import Application | ||
from navigator.brokers.sqs import SQSConsumer | ||
|
||
|
||
async def sqs_callback(*args, **kwargs): | ||
# Handle your SQS callback here | ||
print('Received Message:', args, kwargs) | ||
|
||
app = Application( | ||
port=5001 | ||
) | ||
|
||
sqs = SQSConsumer( | ||
callback=sqs_callback | ||
) | ||
sqs.setup(app) | ||
|
||
if __name__ == '__main__': | ||
try: | ||
app.run() | ||
except KeyboardInterrupt: | ||
print('EXIT FROM APP =========') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Awaitable, Callable, Union, Optional, Any | ||
from navconfig.logging import logging | ||
|
||
|
||
class BrokerConsumer(ABC): | ||
""" | ||
Broker Consumer Interface. | ||
""" | ||
_name_: str = "broker_consumer" | ||
|
||
def __init__( | ||
self, | ||
callback: Optional[Union[Awaitable, Callable]] = None, | ||
**kwargs | ||
): | ||
self._queue_name = kwargs.get('queue_name', 'navigator') | ||
self.logger = logging.getLogger('Broker.Consumer') | ||
self._callback_ = callback if callback else self.subscriber_callback | ||
|
||
@abstractmethod | ||
async def event_subscribe( | ||
self, | ||
queue_name: str, | ||
callback: Union[Callable, Awaitable] | ||
) -> None: | ||
""" | ||
Subscribe to a Queue and consume messages. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
async def subscriber_callback( | ||
self, | ||
message: Any, | ||
body: str | ||
) -> None: | ||
""" | ||
Default Callback for Event Subscription. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def wrap_callback( | ||
self, | ||
callback: Callable[[Any, str], Awaitable[None]], | ||
requeue_on_fail: bool = False, | ||
max_retries: int = 3 | ||
) -> Callable: | ||
""" | ||
Wrap the user-provided callback to handle message decoding and | ||
acknowledgment. | ||
""" |
Oops, something went wrong.