Skip to content

Commit

Permalink
Adding Subscription rules (#14633)
Browse files Browse the repository at this point in the history
* 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
conniey authored Aug 31, 2020
1 parent b9d2ea7 commit 7b1e380
Show file tree
Hide file tree
Showing 34 changed files with 2,633 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@
<!-- False positive as the methods are implemented in an anonymous class that is not exposed publicly. EntityHelper's
accessor classes are not visible. -->
<suppress checks="com.azure.tools.checkstyle.checks.NoImplInPublicAPI" files="com.azure.messaging.servicebus.administration.models.QueueProperties.java"/>
<suppress checks="com.azure.tools.checkstyle.checks.NoImplInPublicAPI" files="com.azure.messaging.servicebus.administration.models.RuleProperties.java"/>
<suppress checks="com.azure.tools.checkstyle.checks.NoImplInPublicAPI" files="com.azure.messaging.servicebus.administration.models.SubscriptionProperties.java"/>
<suppress checks="com.azure.tools.checkstyle.checks.NoImplInPublicAPI" files="com.azure.messaging.servicebus.administration.models.TopicProperties.java"/>

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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;
}
}
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;
}
}
Loading

0 comments on commit 7b1e380

Please sign in to comment.