다음을 통해 공유


CorrelationRuleFilter Class

public class CorrelationRuleFilter
extends RuleFilter

Represents the correlation rule filter expression. It holds a set of conditions that are matched against one or more of an arriving message's user and system properties. A common use case is to match against the message's:

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.

This provides an efficient shortcut for declarations of filters that deal only with correlation equality. In this case the cost of the lexicographical 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).

Sample: Create a topic, subscription, and rule

The following code sample demonstrates the creation of a Service Bus topic and subscription. The subscription filters for messages with a correlation id "emails" and has a "importance" property set to "high". Consequently, all high importance messages will be delivered to the "high-importance-subscription" subscription. See Topic filters for additional information.

String topicName = "my-new-topic";
 TopicProperties topic = client.createTopic(topicName);

 String subscriptionName = "high-importance-subscription";
 String ruleName = "important-emails-filter";
 CreateSubscriptionOptions subscriptionOptions = new CreateSubscriptionOptions()
     .setMaxDeliveryCount(15)
     .setLockDuration(Duration.ofMinutes(2));

 CorrelationRuleFilter ruleFilter = new CorrelationRuleFilter()
     .setCorrelationId("emails");
 ruleFilter.getProperties().put("importance", "high");

 CreateRuleOptions createRuleOptions = new CreateRuleOptions()
     .setFilter(ruleFilter);

 SubscriptionProperties subscription = client.createSubscription(topicName, subscriptionName, ruleName,
     subscriptionOptions, createRuleOptions);

 System.out.printf("Subscription created. Name: %s. Topic name: %s. Lock Duration: %s.%n",
     subscription.getSubscriptionName(), subscription.getTopicName(), subscription.getLockDuration());

Constructor Summary

Constructor Description
CorrelationRuleFilter()

Initializes a new instance of CorrelationRuleFilter with default values.

CorrelationRuleFilter(String correlationId)

Initializes a new instance of CorrelationRuleFilter with default values with the specified correlation identifier.

Method Summary

Modifier and Type Method and Description
boolean equals(Object other)

Compares this RuleFilter to the specified object.

String getContentType()

Gets the content type of the message.

String getCorrelationId()

Gets the correlation identifier.

String getLabel()

Gets the application specific label.

String getMessageId()

Gets the identifier for the message.

Map<String,Object> getProperties()

Gets application specific properties of the message.

String getReplyTo()

Gets the address of the queue or subscription to reply to.

String getReplyToSessionId()

Gets the session identifier to reply to.

String getSessionId()

Gets the session identifier.

String getTo()

Gets the address to send to.

int hashCode()

Returns a hash code for this CorrelationRuleFilter.

CorrelationRuleFilter setContentType(String contentType)

Sets the content type of the message.

CorrelationRuleFilter setCorrelationId(String correlationId)

Sets the correlation identifier.

CorrelationRuleFilter setLabel(String label)

Sets the application specific label.

CorrelationRuleFilter setMessageId(String messageId)

Sets the identifier for the message.

CorrelationRuleFilter setReplyTo(String replyTo)

Sets the address of the queue or subscription to reply to.

CorrelationRuleFilter setReplyToSessionId(String replyToSessionId)

Sets the session identifier to reply to.

CorrelationRuleFilter setSessionId(String sessionId)

Sets the session identifier.

CorrelationRuleFilter setTo(String to)

Sets the address to send to.

String toString()

Converts the value of the current instance to its equivalent string representation.

Methods inherited from java.lang.Object

Constructor Details

CorrelationRuleFilter

public CorrelationRuleFilter()

Initializes a new instance of CorrelationRuleFilter with default values.

CorrelationRuleFilter

public CorrelationRuleFilter(String correlationId)

Initializes a new instance of CorrelationRuleFilter with default values with the specified correlation identifier.

Parameters:

correlationId - The identifier for the correlation.

Method Details

equals

public boolean equals(Object other)

Compares this RuleFilter to the specified object. The result is true if and only if the argument is not null and is a CorrelationRuleFilter object that with the same parameters as this object.

Overrides:

CorrelationRuleFilter.equals(Object other)

Parameters:

other -
  • the object to which the current CorrelationRuleFilter should be compared.

Returns:

True, if the passed object is a CorrelationRuleFilter with the same parameter values, False otherwise.

getContentType

public String getContentType()

Gets the content type of the message.

Returns:

The content type of the message.

getCorrelationId

public String getCorrelationId()

Gets the correlation identifier.

Returns:

The correlation identifier.

getLabel

public String getLabel()

Gets the application specific label.

Returns:

The application specific label.

getMessageId

public String getMessageId()

Gets the identifier for the message.

Returns:

The identifier for the message.

getProperties

public Map getProperties()

Gets application specific properties of the message.

Returns:

The application specific properties of the message.

getReplyTo

public String getReplyTo()

Gets the address of the queue or subscription to reply to.

Returns:

The address of the queue or subscription to reply to.

getReplyToSessionId

public String getReplyToSessionId()

Gets the session identifier to reply to.

Returns:

The session identifier to reply to.

getSessionId

public String getSessionId()

Gets the session identifier.

Returns:

The session identifier.

getTo

public String getTo()

Gets the address to send to.

Returns:

The address to send to.

hashCode

public int hashCode()

Returns a hash code for this CorrelationRuleFilter.

Overrides:

CorrelationRuleFilter.hashCode()

Returns:

a hash code value for this object.

setContentType

public CorrelationRuleFilter setContentType(String contentType)

Sets the content type of the message.

Parameters:

contentType - The content type of the message.

Returns:

The updated CorrelationRuleFilter itself.

setCorrelationId

public CorrelationRuleFilter setCorrelationId(String correlationId)

Sets the correlation identifier.

Parameters:

correlationId - The correlation identifier.

Returns:

The updated CorrelationRuleFilter itself.

setLabel

public CorrelationRuleFilter setLabel(String label)

Sets the application specific label.

Parameters:

label - The application specific label.

Returns:

The updated CorrelationRuleFilter itself.

setMessageId

public CorrelationRuleFilter setMessageId(String messageId)

Sets the identifier for the message.

Parameters:

messageId - The identifier for the message.

Returns:

The updated CorrelationRuleFilter itself.

setReplyTo

public CorrelationRuleFilter setReplyTo(String replyTo)

Sets the address of the queue or subscription to reply to.

Parameters:

replyTo - The address of the queue or subscription to reply to.

Returns:

The updated CorrelationRuleFilter itself.

setReplyToSessionId

public CorrelationRuleFilter setReplyToSessionId(String replyToSessionId)

Sets the session identifier to reply to. Max size of replyToSessionId is 128.

Parameters:

replyToSessionId - The session identifier to reply to.

Returns:

The updated CorrelationRuleFilter itself.

setSessionId

public CorrelationRuleFilter setSessionId(String sessionId)

Sets the session identifier. Max size of sessionId is 128 chars.

Parameters:

sessionId - The session identifier.

Returns:

The updated CorrelationRuleFilter itself.

setTo

public CorrelationRuleFilter setTo(String to)

Sets the address to send to.

Parameters:

to - The address to send to.

Returns:

The updated CorrelationRuleFilter itself.

toString

public String toString()

Converts the value of the current instance to its equivalent string representation.

Overrides:

CorrelationRuleFilter.toString()

Returns:

A string representation of the current instance.

Applies to