-
Notifications
You must be signed in to change notification settings - Fork 3.2k
create_batch feature implementation (#6256) #6324
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
Changes from 1 commit
2d22a1a
11b3333
4f310ea
47df21b
dfd4e39
7e58a0c
fc69d42
e4be05e
e702c76
aa56698
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -261,6 +261,18 @@ def __init__(self, max_message_size=None, partition_key=None): | |
|
|
||
| self._set_partition_key(partition_key) | ||
| self._size = self.message.gather()[0].get_message_encoded_size() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please double check the uAMQP code for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works in our case |
||
| self._count = 0 | ||
|
|
||
| def __len__(self): | ||
| return self._count | ||
|
|
||
| @property | ||
| def size(self): | ||
| """The size in bytes | ||
|
|
||
| :return: int | ||
| """ | ||
| return self._size | ||
|
|
||
| @staticmethod | ||
| def _from_batch(batch_data, partition_key=None): | ||
|
|
@@ -306,6 +318,7 @@ def try_add(self, event_data): | |
|
|
||
| self.message._body_gen.append(event_data) # pylint: disable=protected-access | ||
| self._size = size_after_add | ||
| self._count += 1 | ||
| return True | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| import uuid | ||
| import logging | ||
| import time | ||
| from typing import Iterator, Generator, List, Union | ||
| from typing import Iterable, Union | ||
|
|
||
| from uamqp import constants, errors | ||
| from uamqp import compat | ||
|
|
@@ -110,9 +110,8 @@ def _open(self): | |
| self._connect() | ||
| self.running = True | ||
|
|
||
| self._max_message_size_on_link = self._handler.message_handler._link.peer_max_message_size if\ | ||
| self._handler.message_handler._link.peer_max_message_size\ | ||
| else constants.MAX_MESSAGE_LENGTH_BYTES | ||
| self._max_message_size_on_link = self._handler.message_handler._link.peer_max_message_size \ | ||
| or constants.MAX_MESSAGE_LENGTH_BYTES # pylint: disable=protected-access | ||
|
|
||
| def _connect(self): | ||
| connected = self._build_connection() | ||
|
|
@@ -315,13 +314,13 @@ def create_batch(self, max_message_size=None, partition_key=None): | |
| self._open() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we change the behaviour for the async create_batch (to raise an error if the connection isn't open) we will need to do the same thing here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same to the above async one. We should open internally first to get the right peer link message size. |
||
|
|
||
| if max_message_size and max_message_size > self._max_message_size_on_link: | ||
| raise EventDataError('Max message size: {} is too large, acceptable max batch size is: {} bytes.' | ||
| raise ValueError('Max message size: {} is too large, acceptable max batch size is: {} bytes.' | ||
| .format(max_message_size, self._max_message_size_on_link)) | ||
|
|
||
| return EventDataBatch(max_message_size if max_message_size else self._max_message_size_on_link, partition_key) | ||
| return EventDataBatch(max_message_size or self._max_message_size_on_link, partition_key) | ||
|
|
||
| def send(self, event_data, partition_key=None): | ||
| # type:(Union[EventData, Union[List[EventData], Iterator[EventData], Generator[EventData]]], Union[str, bytes]) -> None | ||
| # type:(Union[EventData, EventDataBatch, Iterable[EventData]], Union[str, bytes]) -> None | ||
| """ | ||
| Sends an event data and blocks until acknowledgement is | ||
| received or operation times out. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can also be done with an "or" statement:
EventDataBatch(max_message_size or self._max_message_size....)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to use "or"