Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Service Bus] ATOM API: Allow configuring the rule with createSubscription #12495

Merged
15 commits merged into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sdk/servicebus/service-bus/review/service-bus.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export interface CreateSubscriptionOptions extends OperationOptions {
deadLetteringOnFilterEvaluationExceptions?: boolean;
deadLetteringOnMessageExpiration?: boolean;
defaultMessageTimeToLive?: string;
defaultRuleOptions?: {
name: string;
filter?: SqlRuleFilter | CorrelationRuleFilter;
action?: SqlRuleAction;
};
enableBatchedOperations?: boolean;
forwardDeadLetteredMessagesTo?: string;
forwardTo?: string;
Expand Down Expand Up @@ -508,7 +513,7 @@ export interface SubscriptionProperties {
status: EntityStatus;
readonly subscriptionName: string;
readonly topicName: string;
userMetadata: string;
userMetadata?: string;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From testing, observed that this is possible to be undefined.

}

// @public
Expand Down
18 changes: 9 additions & 9 deletions sdk/servicebus/service-bus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export { ServiceBusClientOptions } from "./constructorHelpers";
export { CorrelationRuleFilter } from "./core/managementClient";
export {
CreateMessageBatchOptions,
ServiceBusReceiverOptions,
ServiceBusSessionReceiverOptions,
GetMessageIteratorOptions,
MessageHandlers,
ProcessErrorArgs,
PeekMessagesOptions,
ProcessErrorArgs,
ReceiveMessagesOptions,
ServiceBusReceiverOptions,
ServiceBusSessionReceiverOptions,
SubscribeOptions
} from "./models";
export { OperationOptionsBase, TryAddOptions } from "./modelsToBeSharedWithEventHubs";
Expand All @@ -44,19 +44,19 @@ export {
} from "./serializers/topicResourceSerializer";
export {
EntitiesResponse,
WithResponse,
ServiceBusAdministrationClient
ServiceBusAdministrationClient,
WithResponse
} from "./serviceBusAtomManagementClient";
export { ServiceBusClient } from "./serviceBusClient";
export { isServiceBusError, ServiceBusError, ServiceBusErrorCode } from "./serviceBusError";
export {
DeadLetterOptions,
ServiceBusReceivedMessage,
ServiceBusMessage
ServiceBusMessage,
ServiceBusReceivedMessage
} from "./serviceBusMessage";
export { ServiceBusMessageBatch } from "./serviceBusMessageBatch";
export { AuthorizationRule, EntityStatus, EntityAvailabilityStatus } from "./util/utils";
export {
parseServiceBusConnectionString,
ServiceBusConnectionStringProperties
} from "./util/connectionStringUtils";
export { isServiceBusError, ServiceBusError, ServiceBusErrorCode } from "./serviceBusError";
export { AuthorizationRule, EntityAvailabilityStatus, EntityStatus } from "./util/utils";
138 changes: 80 additions & 58 deletions sdk/servicebus/service-bus/src/serializers/ruleResourceSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,79 +157,101 @@ export interface SqlRuleFilter {
/**
* @internal
* @ignore
* RuleResourceSerializer for serializing / deserializing Rule entities
*
* @interface InternalRuleOptions
*/
export class RuleResourceSerializer implements AtomXmlSerializer {
serialize(rule: RuleProperties): object {
const resource: { Name: any; Filter: any; Action: any } = {
Filter: {},
Action: {},
Name: rule.name
};
export interface InternalRuleOptions {
Name: string;
Filter: any;
Action: any;
}

/**
* @internal
* @ignore
*
* @param {CreateRuleOptions} rule
*/
export function buildInternalRuleResource(rule: CreateRuleOptions): InternalRuleOptions {
const resource: InternalRuleOptions = {
Filter: {},
Action: {},
Name: rule.name
};

if (rule.filter == undefined) {
// Defaults to creating a true filter if none specified
if (rule.filter == undefined) {
// Defaults to creating a true filter if none specified
resource.Filter = {
SqlExpression: "1=1"
};
resource.Filter[Constants.XML_METADATA_MARKER] = {
"p4:type": "SqlFilter",
"xmlns:p4": "http://www.w3.org/2001/XMLSchema-instance"
};
} else {
if (rule.filter.hasOwnProperty("sqlExpression")) {
const sqlFilter: SqlRuleFilter = rule.filter as SqlRuleFilter;
resource.Filter = {
SqlExpression: "1=1"
SqlExpression: sqlFilter.sqlExpression,
Parameters: buildInternalRawKeyValuePairs(sqlFilter.sqlParameters, "sqlParameters")
};
resource.Filter[Constants.XML_METADATA_MARKER] = {
"p4:type": "SqlFilter",
"xmlns:p4": "http://www.w3.org/2001/XMLSchema-instance"
};
} else {
if (rule.filter.hasOwnProperty("sqlExpression")) {
const sqlFilter: SqlRuleFilter = rule.filter as SqlRuleFilter;
resource.Filter = {
SqlExpression: sqlFilter.sqlExpression,
Parameters: buildInternalRawKeyValuePairs(sqlFilter.sqlParameters, "sqlParameters")
};
resource.Filter[Constants.XML_METADATA_MARKER] = {
"p4:type": "SqlFilter",
"xmlns:p4": "http://www.w3.org/2001/XMLSchema-instance"
};
} else {
const correlationFilter: CorrelationRuleFilter = rule.filter as CorrelationRuleFilter;

resource.Filter = {
CorrelationId: correlationFilter.correlationId,
Label: correlationFilter.subject,
To: correlationFilter.to,
ReplyTo: correlationFilter.replyTo,
ReplyToSessionId: correlationFilter.replyToSessionId,
ContentType: correlationFilter.contentType,
SessionId: correlationFilter.sessionId,
MessageId: correlationFilter.messageId,
Properties: buildInternalRawKeyValuePairs(
correlationFilter.applicationProperties,
"applicationProperties"
)
};
resource.Filter[Constants.XML_METADATA_MARKER] = {
"p4:type": "CorrelationFilter",
"xmlns:p4": "http://www.w3.org/2001/XMLSchema-instance"
};
}
}
const correlationFilter: CorrelationRuleFilter = rule.filter as CorrelationRuleFilter;

if (rule.action == undefined || rule.action.sqlExpression == undefined) {
// Defaults to creating an empty rule action instance if none specified
resource.Action = {};
resource.Action[Constants.XML_METADATA_MARKER] = {
"p4:type": "EmptyRuleAction",
"xmlns:p4": "http://www.w3.org/2001/XMLSchema-instance"
};
} else {
resource.Action = {
SqlExpression: rule.action.sqlExpression,
Parameters: buildInternalRawKeyValuePairs(rule.action.sqlParameters, "sqlParameters")
resource.Filter = {
CorrelationId: correlationFilter.correlationId,
Label: correlationFilter.subject,
To: correlationFilter.to,
ReplyTo: correlationFilter.replyTo,
ReplyToSessionId: correlationFilter.replyToSessionId,
ContentType: correlationFilter.contentType,
SessionId: correlationFilter.sessionId,
MessageId: correlationFilter.messageId,
Properties: buildInternalRawKeyValuePairs(
correlationFilter.applicationProperties,
"applicationProperties"
)
};
resource.Action[Constants.XML_METADATA_MARKER] = {
"p4:type": "SqlRuleAction",
resource.Filter[Constants.XML_METADATA_MARKER] = {
"p4:type": "CorrelationFilter",
"xmlns:p4": "http://www.w3.org/2001/XMLSchema-instance"
};
}
}

if (rule.action == undefined || rule.action.sqlExpression == undefined) {
// Defaults to creating an empty rule action instance if none specified
resource.Action = {};
resource.Action[Constants.XML_METADATA_MARKER] = {
"p4:type": "EmptyRuleAction",
"xmlns:p4": "http://www.w3.org/2001/XMLSchema-instance"
};
} else {
resource.Action = {
SqlExpression: rule.action.sqlExpression,
Parameters: buildInternalRawKeyValuePairs(rule.action.sqlParameters, "sqlParameters")
};
resource.Action[Constants.XML_METADATA_MARKER] = {
"p4:type": "SqlRuleAction",
"xmlns:p4": "http://www.w3.org/2001/XMLSchema-instance"
};
}

return resource;
}

return serializeToAtomXmlRequest("RuleDescription", resource);
/**
* @internal
* @ignore
* RuleResourceSerializer for serializing / deserializing Rule entities
*/
export class RuleResourceSerializer implements AtomXmlSerializer {
serialize(rule: RuleProperties): object {
return serializeToAtomXmlRequest("RuleDescription", buildInternalRuleResource(rule));
}

async deserialize(response: HttpOperationResponse): Promise<HttpOperationResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

import { HttpOperationResponse, OperationOptions } from "@azure/core-http";
import { CorrelationRuleFilter } from "..";
import {
AtomXmlSerializer,
deserializeAtomXmlResponse,
Expand All @@ -18,6 +19,12 @@ import {
getStringOrUndefined,
getDate
} from "../util/utils";
import {
buildInternalRuleResource,
InternalRuleOptions,
SqlRuleAction,
SqlRuleFilter
} from "./ruleResourceSerializer";

/**
* @internal
Expand All @@ -40,6 +47,9 @@ export function buildSubscriptionOptions(
DeadLetteringOnFilterEvaluationExceptions: getStringOrUndefined(
subscription.deadLetteringOnFilterEvaluationExceptions
),
DefaultRuleDescription: subscription.defaultRuleOptions
? buildInternalRuleResource(subscription.defaultRuleOptions)
: undefined,
MaxDeliveryCount: getStringOrUndefined(subscription.maxDeliveryCount),
EnableBatchedOperations: getStringOrUndefined(subscription.enableBatchedOperations),
Status: getStringOrUndefined(subscription.status),
Expand Down Expand Up @@ -178,6 +188,30 @@ export interface CreateSubscriptionOptions extends OperationOptions {
*/
deadLetteringOnFilterEvaluationExceptions?: boolean;

/**
* Represents the options to create the default rule for the subscription.
*/
defaultRuleOptions?: {
/**
* Name of the rule
*/
name: string;

/**
* Defines the filter expression that the rule evaluates. For `SqlRuleFilter` input,
* the expression string is interpreted as a SQL92 expression which must
* evaluate to True or False. Only one between a `CorrelationRuleFilter` or
* a `SqlRuleFilter` can be defined.
*/
filter?: SqlRuleFilter | CorrelationRuleFilter;

/**
* The SQL like expression that can be executed on the message should the
* associated filter apply.
*/
action?: SqlRuleAction;
};

/**
* The maximum delivery count of messages after which if it is still not settled,
* gets moved to the dead-letter sub-queue.
Expand Down Expand Up @@ -327,7 +361,7 @@ export interface SubscriptionProperties {
* Used to specify textual content such as tags, labels, etc.
* Value must not exceed 1024 bytes encoded in utf-8.
*/
userMetadata: string;
userMetadata?: string;

/**
* Absolute URL or the name of the queue or topic the dead-lettered
Expand Down Expand Up @@ -458,6 +492,8 @@ export interface InternalSubscriptionOptions {
* Availability status of the messaging entity.
*/
EntityAvailabilityStatus?: string;

DefaultRuleDescription?: InternalRuleOptions;
}

/**
Expand Down
8 changes: 0 additions & 8 deletions sdk/servicebus/service-bus/src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,6 @@ export const ENABLE_SUBSCRIPTION_PARTITIONING = "EnableSubscriptionPartitioning"
*/
export const FILTER_MESSAGES_BEFORE_PUBLISHING = "FilteringMessagesBeforePublishing";

/**
* Indicates the default rule description.
*
* @internal
* @ignore
*/
export const DEFAULT_RULE_DESCRIPTION = "DefaultRuleDescription";

/**
* The entity's size in bytes.
*
Expand Down
Loading