-
Notifications
You must be signed in to change notification settings - Fork 9
Implement Direct Reply To Feature #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
33479c2
work in progress
Gsantomaggio 2ab1c3a
direct reply to
Gsantomaggio cee2566
direct reply to
Gsantomaggio aacd982
direct reply to
Gsantomaggio d9c9073
Update rabbitmq_amqp_python_client/consumer.py
Gsantomaggio fd7a06f
Update rabbitmq_amqp_python_client/consumer.py
Gsantomaggio 643cec0
Update examples/direct_reply_queue/direct_reply_to.py
Gsantomaggio acaf44d
Update examples/direct_reply_queue/direct_reply_to.py
Gsantomaggio 9f8f31f
remove pika Exception
Gsantomaggio 2237f51
Merge branch 'feat/direct-reply-to' of github.com:rabbitmq/rabbitmq-a…
Gsantomaggio 4757a78
Address optional
Gsantomaggio 0ec35bb
test
Gsantomaggio 2d0d638
test
Gsantomaggio b74e2bd
add credits
Gsantomaggio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,90 @@ | ||
| # type: ignore | ||
|
|
||
|
|
||
| from rabbitmq_amqp_python_client import ( | ||
| AMQPMessagingHandler, | ||
| Connection, | ||
| Converter, | ||
| DirectReplyToConsumerOptions, | ||
| Environment, | ||
| Event, | ||
| Message, | ||
| OutcomeState, | ||
| ) | ||
|
|
||
| MESSAGES_TO_PUBLISH = 200 | ||
|
|
||
|
|
||
| class MyMessageHandler(AMQPMessagingHandler): | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
| self._count = 0 | ||
|
|
||
| def on_amqp_message(self, event: Event): | ||
| print( | ||
| "received message: {} ".format( | ||
| Converter.bytes_to_string(event.message.body) | ||
| ) | ||
| ) | ||
|
|
||
| # accepting | ||
| self.delivery_context.accept(event) | ||
|
|
||
| self._count = self._count + 1 | ||
| print("count " + str(self._count)) | ||
|
|
||
| if self._count == MESSAGES_TO_PUBLISH: | ||
| print("received all messages") | ||
|
|
||
| def on_connection_closed(self, event: Event): | ||
| # if you want you can add cleanup operations here | ||
| print("connection closed") | ||
|
|
||
| def on_link_closed(self, event: Event) -> None: | ||
| # if you want you can add cleanup operations here | ||
| print("link closed") | ||
|
|
||
|
|
||
| def create_connection(environment: Environment) -> Connection: | ||
| connection = environment.connection() | ||
| connection.dial() | ||
| return connection | ||
|
|
||
|
|
||
| def main() -> None: | ||
| print("connection_consumer to amqp server") | ||
| environment = Environment(uri="amqp://guest:guest@localhost:5672/") | ||
| connection_consumer = create_connection(environment) | ||
| consumer = connection_consumer.consumer( | ||
| message_handler=MyMessageHandler(), | ||
| consumer_options=DirectReplyToConsumerOptions(), | ||
| ) | ||
| addr = consumer.address | ||
| print("connecting to address: {}".format(addr)) | ||
| connection_publisher = create_connection(environment) | ||
| publisher = connection_publisher.publisher(addr) | ||
|
|
||
| for i in range(MESSAGES_TO_PUBLISH): | ||
| msg = Message(body=Converter.string_to_bytes("test message {} ".format(i))) | ||
| status = publisher.publish(msg) | ||
| if status.remote_state == OutcomeState.ACCEPTED: | ||
| print("message accepted") | ||
| elif status.remote_state == OutcomeState.RELEASED: | ||
| print("message not routed") | ||
| elif status.remote_state == OutcomeState.REJECTED: | ||
| print("message rejected") | ||
|
|
||
| try: | ||
| consumer.run() | ||
| except KeyboardInterrupt: | ||
| pass | ||
|
|
||
| consumer.close() | ||
| publisher.close() | ||
| connection_consumer.close() | ||
| connection_publisher.close() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.