SqlRuleFilter Class
- java.
lang. Object - com.
azure. messaging. servicebus. administration. models. RuleFilter - com.
azure. messaging. servicebus. administration. models. SqlRuleFilter
- com.
- com.
public class SqlRuleFilter
extends RuleFilter
Represents a filter which is a composition of an expression and an action that is executed in the pub/sub pipeline.
A SqlRuleFilter holds a SQL-like condition expression that is evaluated in the broker against the arriving messages' user-defined properties and system properties. All system properties (which are all properties explicitly listed on the ServiceBusMessage class) must be prefixed with sys.
in the condition expression. The SQL subset implements testing for existence of properties (EXISTS), testing for null-values (IS NULL), logical NOT/AND/OR, relational operators, numeric arithmetic, and simple text pattern matching with LIKE.
Sample: Create SQL rule filter with SQL rule action
The code sample below creates a rule using a SQL filter and SQL action. The rule matches messages with:
- getCorrelationId() equal to
"email"
- getApplicationProperties() contains a key
"sender"
with value"joseph"
- getApplicationProperties() contains a key
"importance"
with value *"joseph"
OR the value is NULL.
If the filter matches, it will set/update the "importance"
key in getApplicationProperties() with "critical"
.
String topicName = "emails";
String subscriptionName = "important-emails";
String ruleName = "emails-from-joseph";
RuleFilter sqlRuleFilter = new SqlRuleFilter(
"sys.CorrelationId = 'email' AND sender = 'joseph' AND (importance IS NULL OR importance = 'high')");
RuleAction sqlRuleAction = new SqlRuleAction("SET importance = 'critical';");
CreateRuleOptions createRuleOptions = new CreateRuleOptions()
.setFilter(sqlRuleFilter)
.setAction(sqlRuleAction);
RuleProperties rule = client.createRule(topicName, ruleName, subscriptionName, createRuleOptions);
System.out.printf("Rule '%s' created for topic %s, subscription %s. Filter: %s%n", rule.getName(), topicName,
subscriptionName, rule.getFilter());
Constructor Summary
Constructor | Description |
---|---|
SqlRuleFilter(String sqlExpression) |
Creates a new instance with the given SQL expression. |
Method Summary
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other)
Compares this Rule |
Map<String,Object> |
getParameters()
Gets the value of a filter expression. |
String |
getSqlExpression()
Gets the SQL expression. |
int |
hashCode()
Returns a hash code for this Sql |
String |
toString()
Converts the value of the current instance to its equivalent string representation. |
Methods inherited from java.lang.Object
Constructor Details
SqlRuleFilter
public SqlRuleFilter(String sqlExpression)
Creates a new instance with the given SQL expression.
Parameters:
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 SqlRuleFilter object that with the same parameters as this object.
Overrides:
SqlRuleFilter.equals(Object other)Parameters:
- the object to which the current SqlRuleFilter should be compared.
Returns:
getParameters
public Map
Gets the value of a filter expression. Allowed types: string, int, long, bool, double
Returns:
getSqlExpression
public String getSqlExpression()
Gets the SQL expression.
Returns:
hashCode
public int hashCode()
Returns a hash code for this SqlRuleFilter, which is the hashcode for the SqlExpression.
Overrides:
SqlRuleFilter.hashCode()Returns:
toString
public String toString()
Converts the value of the current instance to its equivalent string representation.
Overrides:
SqlRuleFilter.toString()Returns:
Applies to
Azure SDK for Java