Skip to content

Commit

Permalink
Refactor move servicebus message state key to azure-core-amqp (#29309)
Browse files Browse the repository at this point in the history
* Move servicebus message state key to amqp core

* update pom

* update CHANGELOG
  • Loading branch information
ZejiaJiang authored Jun 30, 2022
1 parent d52e9d7 commit 04ac4f9
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ com.azure.tools:azure-sdk-build-tool;1.0.0-beta.1;1.0.0-beta.2
# note: The unreleased dependencies will not be manipulated with the automatic PR creation code.
# In the pom, the version update tag after the version should name the unreleased package and the dependency version:
# <!-- {x-version-update;unreleased_com.azure:azure-core;dependency} -->
unreleased_com.azure:azure-core-amqp;2.6.0-beta.1

# Released Beta dependencies: Copy the entry from above, prepend "beta_", remove the current
# version and set the version to the released beta. Released beta dependencies are only valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ public enum AmqpMessageConstant {
/**
* The identifier for deadletter reason.
*/
DEAD_LETTER_REASON_ANNOTATION_NAME("DeadLetterReason");
DEAD_LETTER_REASON_ANNOTATION_NAME("DeadLetterReason"),
/**
* The state of message.
*/
MESSAGE_STATE_ANNOTATION_NAME("x-opt-message-state");


private static final Map<String, AmqpMessageConstant> RESERVED_CONSTANTS_MAP = new HashMap<>();
private final String constant;
Expand Down
1 change: 1 addition & 0 deletions sdk/servicebus/azure-messaging-servicebus/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Bugs Fixed

### Other Changes
- Moved message state key to `azure-core-amqp` constants. ([#26898](https://github.com/Azure/azure-sdk-for-java/issues/26898))

## 7.9.1 (2022-06-16)

Expand Down
2 changes: 1 addition & 1 deletion sdk/servicebus/azure-messaging-servicebus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-amqp</artifactId>
<version>2.5.2</version> <!-- {x-version-update;com.azure:azure-core-amqp;dependency} -->
<version>2.6.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-amqp;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static com.azure.core.amqp.AmqpMessageConstant.PARTITION_KEY_ANNOTATION_NAME;
import static com.azure.core.amqp.AmqpMessageConstant.SCHEDULED_ENQUEUE_UTC_TIME_NAME;
import static com.azure.core.amqp.AmqpMessageConstant.SEQUENCE_NUMBER_ANNOTATION_NAME;
import static com.azure.core.amqp.AmqpMessageConstant.MESSAGE_STATE_ANNOTATION_NAME;

/**
* The data structure encapsulating the message received from Service Bus. The message structure is discussed in detail
Expand All @@ -53,8 +54,6 @@ public final class ServiceBusReceivedMessage {
private boolean isSettled = false;
private Context context;

static final String SERVICE_BUS_MESSAGE_STATE_KEY = "x-opt-message-state";

ServiceBusReceivedMessage(BinaryData body) {
Objects.requireNonNull(body, "'body' cannot be null.");
amqpAnnotatedMessage = new AmqpAnnotatedMessage(AmqpMessageBody.fromData(body.toBytes()));
Expand Down Expand Up @@ -455,7 +454,7 @@ public String getSessionId() {
* @throws UnsupportedOperationException if the message state is an unknown value.
*/
public ServiceBusMessageState getState() {
final Object value = amqpAnnotatedMessage.getMessageAnnotations().get(SERVICE_BUS_MESSAGE_STATE_KEY);
final Object value = amqpAnnotatedMessage.getMessageAnnotations().get(MESSAGE_STATE_ANNOTATION_NAME.getValue());

if (value instanceof Integer) {
return ServiceBusMessageState.fromValue((Integer) value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import static com.azure.core.amqp.AmqpMessageConstant.ENQUEUED_TIME_UTC_ANNOTATION_NAME;
import static com.azure.core.amqp.AmqpMessageConstant.LOCKED_UNTIL_KEY_ANNOTATION_NAME;
import static com.azure.core.amqp.AmqpMessageConstant.SEQUENCE_NUMBER_ANNOTATION_NAME;
import static com.azure.messaging.servicebus.ServiceBusReceivedMessage.SERVICE_BUS_MESSAGE_STATE_KEY;
import static com.azure.core.amqp.AmqpMessageConstant.MESSAGE_STATE_ANNOTATION_NAME;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -167,7 +167,7 @@ public static Stream<Arguments> canGetMessageState() {
public void canGetMessageState(Integer value, ServiceBusMessageState expected) {
// Arrange
final ServiceBusReceivedMessage message = new ServiceBusReceivedMessage(PAYLOAD_BINARY);
message.getRawAmqpMessage().getMessageAnnotations().put(SERVICE_BUS_MESSAGE_STATE_KEY, value);
message.getRawAmqpMessage().getMessageAnnotations().put(MESSAGE_STATE_ANNOTATION_NAME.getValue(), value);

// Act
final ServiceBusMessageState actual = message.getState();
Expand All @@ -187,7 +187,7 @@ public void defaultMessageState() {
public void throwsOnInvalidMessageState() {
// Arrange
final ServiceBusReceivedMessage message = new ServiceBusReceivedMessage(PAYLOAD_BINARY);
message.getRawAmqpMessage().getMessageAnnotations().put(SERVICE_BUS_MESSAGE_STATE_KEY, 10);
message.getRawAmqpMessage().getMessageAnnotations().put(MESSAGE_STATE_ANNOTATION_NAME.getValue(), 10);

// Act & Assert
assertThrows(UnsupportedOperationException.class, () -> message.getState());
Expand Down

0 comments on commit 04ac4f9

Please sign in to comment.