-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding create rules. * Adding RuleAction and RuleFilter. * Adding overloads in ServiceBusAdministrationClient and ServiceBusAdministrationAsyncClient. * Regenerate swagger. KeyValue names are changed. * Renaming generated swagger classes to `*Impl` to avoid name conflicts.
- Loading branch information
Showing
34 changed files
with
2,633 additions
and
105 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
530 changes: 519 additions & 11 deletions
530
...va/com/azure/messaging/servicebus/administration/ServiceBusAdministrationAsyncClient.java
Large diffs are not rendered by default.
Oops, something went wrong.
255 changes: 242 additions & 13 deletions
255
...in/java/com/azure/messaging/servicebus/administration/ServiceBusAdministrationClient.java
Large diffs are not rendered by default.
Oops, something went wrong.
294 changes: 294 additions & 0 deletions
294
...main/java/com/azure/messaging/servicebus/administration/models/CorrelationRuleFilter.java
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,294 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.messaging.servicebus.administration.models; | ||
|
||
import com.azure.core.annotation.Fluent; | ||
import com.azure.core.util.logging.ClientLogger; | ||
import com.azure.messaging.servicebus.ServiceBusMessage; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Represents the correlation rule filter expression. | ||
* <p> | ||
* A CorrelationRuleFilter holds a set of conditions that are matched against one of more of an arriving message's user | ||
* and system properties. A common use is a match against the {@link ServiceBusMessage#getCorrelationId()} property, but | ||
* the application can also choose to match against {@link ServiceBusMessage#getContentType()}, {@link | ||
* ServiceBusMessage#getLabel()}, {@link ServiceBusMessage#getMessageId()}, {@link ServiceBusMessage#getReplyTo()}, | ||
* {@link ServiceBusMessage#getReplyToSessionId()}, {@link ServiceBusMessage#getSessionId()}, {@link | ||
* ServiceBusMessage#getTo()}, and any user-defined properties. A match exists when an arriving message's value for a | ||
* property is equal to the value specified in the correlation filter. For string expressions, the comparison is | ||
* case-sensitive. When specifying multiple match properties, the filter combines them as a logical AND condition, | ||
* meaning all conditions must match for the filter to match. | ||
* </p> | ||
* <p> | ||
* The CorrelationRuleFilter provides an efficient shortcut for declarations of filters that deal only with correlation | ||
* equality. In this case the cost of the lexigraphical analysis of the expression can be avoided. Not only will | ||
* correlation filters be optimized at declaration time, but they will also be optimized at runtime. Correlation filter | ||
* matching can be reduced to a hashtable lookup, which aggregates the complexity of the set of defined correlation | ||
* filters to O(1). | ||
* </p> | ||
*/ | ||
@Fluent | ||
public class CorrelationRuleFilter extends RuleFilter { | ||
private final Map<String, Object> properties = new HashMap<>(); | ||
private String correlationId; | ||
private String contentType; | ||
private String label; | ||
private String messageId; | ||
private String replyTo; | ||
private String replyToSessionId; | ||
private String sessionId; | ||
private String to; | ||
|
||
/** | ||
* Initializes a new instance of {@link CorrelationRuleFilter} with default values. | ||
*/ | ||
public CorrelationRuleFilter() { | ||
this.correlationId = null; | ||
} | ||
|
||
/** | ||
* Initializes a new instance of {@link CorrelationRuleFilter} with default values with the specified correlation | ||
* identifier. | ||
* | ||
* @param correlationId The identifier for the correlation. | ||
* | ||
* @throws IllegalArgumentException If {@code correlationId} is an empty string. | ||
* @throws NullPointerException If {@code correlationId} is null. | ||
*/ | ||
public CorrelationRuleFilter(String correlationId) { | ||
final ClientLogger logger = new ClientLogger(CorrelationRuleFilter.class); | ||
if (correlationId == null) { | ||
throw logger.logExceptionAsError(new NullPointerException("'correlationId' cannot be null")); | ||
} else if (correlationId.isEmpty()) { | ||
throw logger.logExceptionAsError(new IllegalArgumentException("'correlationId' cannot be empty.")); | ||
} | ||
|
||
this.correlationId = correlationId; | ||
} | ||
|
||
/** | ||
* Gets the content type of the message. | ||
* | ||
* @return The content type of the message. | ||
*/ | ||
public String getContentType() { | ||
return contentType; | ||
} | ||
|
||
/** | ||
* Sets the content type of the message. | ||
* | ||
* @param contentType The content type of the message. | ||
* | ||
* @return The updated {@link CorrelationRuleFilter} itself. | ||
*/ | ||
public CorrelationRuleFilter setContentType(String contentType) { | ||
this.contentType = contentType; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets the correlation identifier. | ||
* | ||
* @return The correlation identifier. | ||
*/ | ||
public String getCorrelationId() { | ||
return correlationId; | ||
} | ||
|
||
/** | ||
* Sets the correlation identifier. | ||
* | ||
* @param correlationId The correlation identifier. | ||
* | ||
* @return The updated {@link CorrelationRuleFilter} itself. | ||
*/ | ||
public CorrelationRuleFilter setCorrelationId(String correlationId) { | ||
this.correlationId = correlationId; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets the application specific label. | ||
* | ||
* @return The application specific label. | ||
*/ | ||
public String getLabel() { | ||
return label; | ||
} | ||
|
||
/** | ||
* Sets the application specific label. | ||
* | ||
* @param label The application specific label. | ||
* | ||
* @return The updated {@link CorrelationRuleFilter} itself. | ||
*/ | ||
public CorrelationRuleFilter setLabel(String label) { | ||
this.label = label; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets the identifier for the message. | ||
* | ||
* @return The identifier for the message. | ||
*/ | ||
public String getMessageId() { | ||
return messageId; | ||
} | ||
|
||
/** | ||
* Sets the identifier for the message. | ||
* | ||
* @param messageId The identifier for the message. | ||
* | ||
* @return The updated {@link CorrelationRuleFilter} itself. | ||
*/ | ||
public CorrelationRuleFilter setMessageId(String messageId) { | ||
this.messageId = messageId; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets application specific properties of the message. | ||
* | ||
* @return The application specific properties of the message. | ||
*/ | ||
public Map<String, Object> getProperties() { | ||
return properties; | ||
} | ||
|
||
/** | ||
* Gets the address of the queue or subscription to reply to. | ||
* | ||
* @return The address of the queue or subscription to reply to. | ||
*/ | ||
public String getReplyTo() { | ||
return replyTo; | ||
} | ||
|
||
/** | ||
* Sets the address of the queue or subscription to reply to. | ||
* | ||
* @param replyTo The address of the queue or subscription to reply to. | ||
* | ||
* @return The updated {@link CorrelationRuleFilter} itself. | ||
*/ | ||
public CorrelationRuleFilter setReplyTo(String replyTo) { | ||
this.replyTo = replyTo; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets the session identifier to reply to. | ||
* | ||
* @return The session identifier to reply to. | ||
*/ | ||
public String getReplyToSessionId() { | ||
return replyToSessionId; | ||
} | ||
|
||
/** | ||
* Sets the session identifier to reply to. Max size of {@code replyToSessionId} is 128. | ||
* | ||
* @param replyToSessionId The session identifier to reply to. | ||
* | ||
* @return The updated {@link CorrelationRuleFilter} itself. | ||
*/ | ||
public CorrelationRuleFilter setReplyToSessionId(String replyToSessionId) { | ||
this.replyToSessionId = replyToSessionId; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets the session identifier. | ||
* | ||
* @return The session identifier. | ||
*/ | ||
public String getSessionId() { | ||
return sessionId; | ||
} | ||
|
||
/** | ||
* Sets the session identifier. Max size of {@code sessionId} is 128 chars. | ||
* | ||
* @param sessionId The session identifier. | ||
* | ||
* @return The updated {@link CorrelationRuleFilter} itself. | ||
*/ | ||
public CorrelationRuleFilter setSessionId(String sessionId) { | ||
this.sessionId = sessionId; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets the address to send to. | ||
* | ||
* @return The address to send to. | ||
*/ | ||
public String getTo() { | ||
return to; | ||
} | ||
|
||
/** | ||
* Sets the address to send to. | ||
* | ||
* @param to The address to send to. | ||
* | ||
* @return The updated {@link CorrelationRuleFilter} itself. | ||
*/ | ||
public CorrelationRuleFilter setTo(String to) { | ||
this.to = to; | ||
return this; | ||
} | ||
|
||
/** | ||
* Converts the value of the current instance to its equivalent string representation. | ||
* | ||
* @return A string representation of the current instance. | ||
*/ | ||
@Override | ||
public String toString() { | ||
final StringBuilder builder = new StringBuilder("CorrelationRuleFilter: "); | ||
|
||
boolean isFirstExpression = appendPropertyExpression(true, builder, "sys.CorrelationId", | ||
correlationId); | ||
isFirstExpression = appendPropertyExpression(isFirstExpression, builder, "sys.MessageId", | ||
messageId); | ||
isFirstExpression = appendPropertyExpression(isFirstExpression, builder, "sys.To", to); | ||
isFirstExpression = appendPropertyExpression(isFirstExpression, builder, "sys.ReplyTo", replyTo); | ||
isFirstExpression = appendPropertyExpression(isFirstExpression, builder, "sys.Label", label); | ||
isFirstExpression = appendPropertyExpression(isFirstExpression, builder, "sys.SessionId", sessionId); | ||
isFirstExpression = appendPropertyExpression(isFirstExpression, builder, "sys.ReplyToSessionId", | ||
replyToSessionId); | ||
isFirstExpression = appendPropertyExpression(isFirstExpression, builder, "sys.ContentType", | ||
contentType); | ||
|
||
for (Map.Entry<String, Object> entry : properties.entrySet()) { | ||
isFirstExpression = appendPropertyExpression(isFirstExpression, builder, entry.getKey(), | ||
entry.getValue().toString()); | ||
} | ||
|
||
return builder.toString(); | ||
} | ||
|
||
private static boolean appendPropertyExpression(boolean isFirstExpression, StringBuilder builder, String display, | ||
String value) { | ||
|
||
if (value == null) { | ||
return true; | ||
} | ||
|
||
if (!isFirstExpression) { | ||
builder.append(" AND "); | ||
} | ||
|
||
builder.append(String.format("%s = '%s'", display, value)); | ||
return false; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...src/main/java/com/azure/messaging/servicebus/administration/models/CreateRuleOptions.java
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,87 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.messaging.servicebus.administration.models; | ||
|
||
import com.azure.core.annotation.Fluent; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* A set of options for creating a rule. | ||
*/ | ||
@Fluent | ||
public class CreateRuleOptions { | ||
private RuleFilter filter; | ||
private RuleAction action; | ||
|
||
/** | ||
* Initializes a new instance with the {@link TrueRuleFilter}. | ||
*/ | ||
public CreateRuleOptions() { | ||
this(TrueRuleFilter.getInstance()); | ||
} | ||
|
||
/** | ||
* Initializes a new instance with the given rule {@code name} and {@code filter}. | ||
* | ||
* @param filter Filter expression used to match messages. | ||
* @throws NullPointerException if {@code filter} is null. | ||
*/ | ||
public CreateRuleOptions(RuleFilter filter) { | ||
this.filter = Objects.requireNonNull(filter, "'filter' cannot be null."); | ||
} | ||
|
||
/** | ||
* Initializes a new instance with the given rule properties. | ||
* | ||
* @param ruleProperties Rule properties to create new rule from. | ||
* @throws NullPointerException if {@code ruleProperties} is null. | ||
*/ | ||
public CreateRuleOptions(RuleProperties ruleProperties) { | ||
Objects.requireNonNull(ruleProperties, "'ruleProperties' cannot be null."); | ||
|
||
this.filter = ruleProperties.getFilter(); | ||
this.action = ruleProperties.getAction(); | ||
} | ||
|
||
/** | ||
* Gets the action to perform if the message satisfies the filtering expression. | ||
* | ||
* @return The action to perform if the message satisfies the filtering expression. | ||
*/ | ||
public RuleAction getAction() { | ||
return action; | ||
} | ||
|
||
/** | ||
* Sets the action to perform if the message satisfies the filtering expression. | ||
* | ||
* @param action The action to perform if the message satisfies the filtering expression. | ||
* @return The updated {@link CreateRuleOptions} object. | ||
*/ | ||
public CreateRuleOptions setAction(RuleAction action) { | ||
this.action = action; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets the filter expression used to match messages. | ||
* | ||
* @return The filter expression used to match messages. | ||
*/ | ||
public RuleFilter getFilter() { | ||
return filter; | ||
} | ||
|
||
/** | ||
* Sets the filter expression used to match messages. | ||
* | ||
* @param filter The filter expression used to match messages. | ||
* @return The updated {@link CreateRuleOptions} object. | ||
*/ | ||
public CreateRuleOptions setFilter(RuleFilter filter) { | ||
this.filter = Objects.requireNonNull(filter, "'filter' cannot be null."); | ||
return this; | ||
} | ||
} |
Oops, something went wrong.