Skip to content

ServiceBus Extension Parity to .NET #201

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 4 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions azure/functions/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ class ServiceBusMessage(abc.ABC):
def get_body(self) -> typing.Union[str, bytes]:
pass

@property
@abc.abstractmethod
def application_properties(self) -> typing.Dict[str, typing.Any]:
pass

@property
@abc.abstractmethod
def content_type(self) -> typing.Optional[str]:
Expand All @@ -457,6 +462,16 @@ def content_type(self) -> typing.Optional[str]:
def correlation_id(self) -> typing.Optional[str]:
pass

@property
@abc.abstractmethod
def dead_letter_error_description(self) -> typing.Optional[str]:
pass

@property
@abc.abstractmethod
def dead_letter_reason(self) -> typing.Optional[str]:
pass

@property
@abc.abstractmethod
def dead_letter_source(self) -> typing.Optional[str]:
Expand All @@ -467,6 +482,11 @@ def dead_letter_source(self) -> typing.Optional[str]:
def delivery_count(self) -> typing.Optional[int]:
pass

@property
@abc.abstractmethod
def enqueued_sequence_number(self) -> typing.Optional[int]:
pass

@property
@abc.abstractmethod
def enqueued_time_utc(self) -> typing.Optional[datetime.datetime]:
Expand All @@ -488,6 +508,11 @@ def expiration_time(self) -> typing.Optional[datetime.datetime]:
def label(self) -> typing.Optional[str]:
pass

@property
@abc.abstractmethod
def locked_until(self) -> typing.Optional[datetime.datetime]:
pass

@property
@abc.abstractmethod
def lock_token(self) -> typing.Optional[str]:
Expand Down Expand Up @@ -534,6 +559,16 @@ def sequence_number(self) -> typing.Optional[int]:
def session_id(self) -> typing.Optional[str]:
pass

@property
@abc.abstractmethod
def state(self) -> typing.Optional[int]:
pass

@property
@abc.abstractmethod
def subject(self) -> typing.Optional[str]:
pass

@property
@abc.abstractmethod
def time_to_live(self) -> typing.Optional[datetime.timedelta]:
Expand All @@ -544,6 +579,11 @@ def time_to_live(self) -> typing.Optional[datetime.timedelta]:
def to(self) -> typing.Optional[str]:
pass

@property
@abc.abstractmethod
def transaction_partition_key(self) -> typing.Optional[str]:
pass

@property
@abc.abstractmethod
def user_properties(self) -> typing.Dict[str, typing.Any]:
Expand Down
118 changes: 118 additions & 0 deletions azure/functions/_servicebus.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ def __init__(self, *,
if body is not None:
self.__set_body(body)

@property
def application_properties(self) -> Dict[str, Any]:
"""Gets the application properties bag, which can be used for
custom message metadata.

Returns:
--------
Dict[str, Any]:
If user has set application properties for the message,
returns a dictionary.
If nothing is set, returns an empty dictionary.
"""
return {}

@property
def content_type(self) -> Optional[str]:
"""Optionally describes the payload of the message,
Expand All @@ -59,6 +73,30 @@ def correlation_id(self) -> Optional[str]:
"""
return self.__correlation_id

@property
def dead_letter_error_description(self) -> Optional[str]:
"""Optionally describes the dead letter error description for the message.

Returns:
--------
Optional[str]
If dead letter error description is set, returns a string.
Otherwise, returns None.
"""
return None

@property
def dead_letter_reason(self) -> Optional[str]:
"""Optionally describes the dead letter reason description for the message.

Returns:
--------
Optional[str]
If dead letter reason description is set, returns a string.
Otherwise, returns None.
"""
return None

@property
def dead_letter_source(self) -> Optional[str]:
"""Only set in messages that have been dead-lettered and subsequently
Expand Down Expand Up @@ -89,6 +127,21 @@ def delivery_count(self) -> Optional[int]:
"""
return None

@property
def enqueued_sequence_number(self) -> Optional[int]:
"""For messages that have been auto-forwarded, this property reflects
the sequence number that had first been assigned to the message at its
original point of submission. This property is read-only. Optionally
describes the enqueued sequence number of the message.

Returns:
--------
Optional[int]
If enqueued sequence number is set, returns an integer.
Otherwise, returns None.
"""
return None

@property
def enqueued_time_utc(self) -> Optional[datetime.datetime]:
"""The UTC instant at which the message has been accepted and stored
Expand Down Expand Up @@ -138,6 +191,24 @@ def label(self) -> Optional[str]:
"""
return None

@property
def locked_until(self) -> Optional[datetime.datetime]:
"""For messages retrieved under a lock (peek-lock receive mode, not
pre-settled) this property reflects the UTC instant until which the
message is held locked in the queue/subscription. When the lock
expires, the DeliveryCount is incremented and the message is again
available for retrieval. This property is read-only.Optionally
describes the date and time in UTC until which the message will be
locked in the queue/subscription.

Returns:
--------
Optional[datetime.datetime]
If locked until is set, returns a datetime.
Otherwise, returns None.
"""
return None

@property
def lock_token(self) -> Optional[str]:
""" The lock token is a reference to the lock that is being held by
Expand Down Expand Up @@ -267,6 +338,37 @@ def session_id(self) -> Optional[str]:
"""
return None

@property
def state(self) -> Optional[int]:
"""The state of the message can be Active, Deferred, or Scheduled.
Deferred messages have Deferred state, scheduled messages have
Scheduled state, all other messages have Active state. States are
represented by corresponding integer values. Active = 0,
Deferred = 1, Scheduled = 2.

Returns:
--------
Optional[int]
If state is set, returns an integer.
Otherwise, returns None.
"""
return None

@property
def subject(self) -> Optional[str]:
"""This property enables the application to indicate the purpose of the
message to the receiver in a standardized fashion, similar to an email
subject line. The mapped AMQP property is "subject". Optionally
describes the application specific label.

Returns:
--------
Optional[str]
If subject is set, returns a string.
Otherwise, returns None.
"""
return None

@property
def time_to_live(self) -> Optional[datetime.timedelta]:
""" This value is the relative duration after which the message
Expand Down Expand Up @@ -300,6 +402,22 @@ def to(self) -> Optional[str]:
"""
return None

@property
def transaction_partition_key(self) -> Optional[str]:
"""If a message is sent via a transfer queue in the scope of a transaction,
this value selects the transfer queue partition: This is functionally
equivalent to PartitionKey and ensures that messages are kept together
and in order as they are transferred. Optionally describes the
partition key. Maximum length is 128 characters.

Returns:
--------
Optional[str]
If transaction partition key is set, returns a string.
Otherwise, returns None.
"""
return None

@property
def user_properties(self) -> Dict[str, Any]:
"""Contains user defined message properties.
Expand Down
Loading