[Service Bus] Msg property renames, sku enums, mandatory sqlExpression in rules #11701 (#11782)

This commit is contained in:
Mohsin Mehmood 2020-10-16 13:13:15 +08:00 коммит произвёл GitHub
Родитель 5646d4b9af
Коммит 1152ea0f9f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
16 изменённых файлов: 151 добавлений и 107 удалений

Просмотреть файл

@ -14,6 +14,10 @@
- [Bug Fix] `sendMessages` method on the sender would have previously thrown an error for sending a batch or an array of messages upon a network disconnect, the issue has been fixed now.
[PR 11651](https://github.com/Azure/azure-sdk-for-js/pull/11651/commits/f262e4562eb78828ee816a54f9a9778692e0eff9)
- Added new "userId" property to `ServiceBusMessage` interface. [PR 11810](https://github.com/Azure/azure-sdk-for-js/pull/11810)
- `NamespaceProperties` interface property "messageSku" type changed from "string" to string literal type "Basic" | "Premium" | "Standard". [PR 11810](https://github.com/Azure/azure-sdk-for-js/pull/11810)
### New features:
- Message locks can be auto-renewed in all receive methods (receiver.receiveMessages, receiver.subcribe
@ -32,6 +36,13 @@
- `acceptSession`, which opens a session by name
- `acceptNextSession`, which opens the next available session, determined by Service Bus.
- as part of this `CreateSessionReceiverOptions` has been renamed to `AcceptSessionReceiverOptions` to conform to guidelines.
- `ServiceBusMessage` interface updates:
- "properties" renamed to "applicationProperties"
- "label" renamed to "subject"
- `CorrelationRuleFilter` interface updates:
- "properties" renamed to "applicationProperties"
- "label" renamed to "subject"
- `SqlRuleFilter` interface "sqlExpression" changed from optional to required
## 7.0.0-preview.6 (2020-09-10)

Просмотреть файл

@ -86,16 +86,16 @@ export type AuthorizationRule = {
// @public
export interface CorrelationRuleFilter {
contentType?: string;
correlationId?: string;
label?: string;
messageId?: string;
properties?: {
applicationProperties?: {
[key: string]: string | number | boolean | Date;
};
contentType?: string;
correlationId?: string;
messageId?: string;
replyTo?: string;
replyToSessionId?: string;
sessionId?: string;
subject?: string;
to?: string;
}
@ -202,7 +202,7 @@ export { MessagingError }
// @public
export interface NamespaceProperties {
createdAt: Date;
messagingSku: string;
messagingSku: "Basic" | "Premium" | "Standard";
messagingUnits: number | undefined;
modifiedAt: Date;
name: string;
@ -363,21 +363,22 @@ export interface ServiceBusClientOptions {
// @public
export interface ServiceBusMessage {
applicationProperties?: {
[key: string]: number | boolean | string | Date;
};
body: any;
contentType?: string;
correlationId?: string | number | Buffer;
label?: string;
messageId?: string | number | Buffer;
partitionKey?: string;
properties?: {
[key: string]: number | boolean | string | Date;
};
replyTo?: string;
replyToSessionId?: string;
scheduledEnqueueTimeUtc?: Date;
sessionId?: string;
subject?: string;
timeToLive?: number;
to?: string;
userId?: string;
viaPartitionKey?: string;
}
@ -472,7 +473,7 @@ export type SqlRuleAction = {
// @public
export interface SqlRuleFilter {
sqlExpression?: string;
sqlExpression: string;
sqlParameters?: {
[key: string]: string | number | boolean;
};

Просмотреть файл

@ -107,9 +107,9 @@ export interface CorrelationRuleFilter {
*/
replyTo?: string;
/**
* Value to be matched with the `label` property of the incoming message.
* Value to be matched with the `subject` property of the incoming message.
*/
label?: string;
subject?: string;
/**
* Value to be matched with the `sessionId` property of the incoming message.
*/
@ -125,7 +125,7 @@ export interface CorrelationRuleFilter {
/**
* Value to be matched with the user properties of the incoming message.
*/
properties?: { [key: string]: string | number | boolean | Date };
applicationProperties?: { [key: string]: string | number | boolean | Date };
}
/**
@ -137,11 +137,11 @@ const correlationProperties = [
"messageId",
"to",
"replyTo",
"label",
"subject",
"sessionId",
"replyToSessionId",
"contentType",
"properties"
"applicationProperties"
];
/**
@ -1140,11 +1140,11 @@ export class ManagementClient extends LinkEntity<RequestResponseLink> {
messageId: this._safelyGetTypedValueFromArray(filtersRawData.value, 1),
to: this._safelyGetTypedValueFromArray(filtersRawData.value, 2),
replyTo: this._safelyGetTypedValueFromArray(filtersRawData.value, 3),
label: this._safelyGetTypedValueFromArray(filtersRawData.value, 4),
subject: this._safelyGetTypedValueFromArray(filtersRawData.value, 4),
sessionId: this._safelyGetTypedValueFromArray(filtersRawData.value, 5),
replyToSessionId: this._safelyGetTypedValueFromArray(filtersRawData.value, 6),
contentType: this._safelyGetTypedValueFromArray(filtersRawData.value, 7),
properties: this._safelyGetTypedValueFromArray(filtersRawData.value, 8)
applicationProperties: this._safelyGetTypedValueFromArray(filtersRawData.value, 8)
};
break;
default:
@ -1265,11 +1265,11 @@ export class ManagementClient extends LinkEntity<RequestResponseLink> {
"message-id": filter.messageId,
to: filter.to,
"reply-to": filter.replyTo,
label: filter.label,
subject: filter.subject,
"session-id": filter.sessionId,
"reply-to-session-id": filter.replyToSessionId,
"content-type": filter.contentType,
properties: filter.properties
applicationProperties: filter.applicationProperties
};
break;
}

Просмотреть файл

@ -30,16 +30,16 @@ export function instrumentServiceBusMessage(
message: ServiceBusMessage,
span: Span
): ServiceBusMessage {
if (message.properties && message.properties[TRACEPARENT_PROPERTY]) {
if (message.applicationProperties && message.applicationProperties[TRACEPARENT_PROPERTY]) {
return message;
}
// create a copy so the original isn't modified
message = { ...message, properties: { ...message.properties } };
message = { ...message, applicationProperties: { ...message.applicationProperties } };
const traceParent = getTraceParentHeader(span.context());
if (traceParent) {
message.properties![TRACEPARENT_PROPERTY] = traceParent;
message.applicationProperties![TRACEPARENT_PROPERTY] = traceParent;
}
return message;
@ -54,11 +54,11 @@ export function instrumentServiceBusMessage(
export function extractSpanContextFromServiceBusMessage(
message: ServiceBusMessage
): SpanContext | undefined {
if (!message.properties || !message.properties[TRACEPARENT_PROPERTY]) {
if (!message.applicationProperties || !message.applicationProperties[TRACEPARENT_PROPERTY]) {
return;
}
const diagnosticId = message.properties[TRACEPARENT_PROPERTY] as string;
const diagnosticId = message.applicationProperties[TRACEPARENT_PROPERTY] as string;
return extractSpanContextFromTraceParentHeader(diagnosticId);
}

Просмотреть файл

@ -24,7 +24,7 @@ export interface NamespaceProperties {
* The SKU/tier of the namespace.
* "Basic", "Standard" and "Premium"
*/
messagingSku: string;
messagingSku: "Basic" | "Premium" | "Standard";
/**
* The last time at which the namespace was modified.
*/
@ -53,7 +53,9 @@ export interface NamespaceProperties {
* @param rawNamespace
*/
export function buildNamespace(rawNamespace: any): NamespaceProperties {
const messagingSku = getString(rawNamespace["MessagingSKU"], "messagingSku");
const messagingSku = <"Basic" | "Premium" | "Standard">(
getString(rawNamespace["MessagingSKU"], "messagingSku")
);
return {
createdAt: getDate(rawNamespace["CreatedTime"], "createdAt"),
messagingSku: messagingSku,

Просмотреть файл

@ -44,14 +44,17 @@ function getTopicFilter(value: any): SqlRuleFilter | CorrelationRuleFilter {
} else {
result = {
correlationId: getStringOrUndefined(value["CorrelationId"]),
label: getStringOrUndefined(value["Label"]),
subject: getStringOrUndefined(value["Label"]),
to: getStringOrUndefined(value["To"]),
replyTo: getStringOrUndefined(value["ReplyTo"]),
replyToSessionId: getStringOrUndefined(value["ReplyToSessionId"]),
sessionId: getStringOrUndefined(value["SessionId"]),
messageId: getStringOrUndefined(value["MessageId"]),
contentType: getStringOrUndefined(value["ContentType"]),
properties: getKeyValuePairsOrUndefined(value["Properties"], "UserProperties")
applicationProperties: getKeyValuePairsOrUndefined(
value["Properties"],
"ApplicationProperties"
)
};
}
return result;
@ -143,7 +146,7 @@ export interface SqlRuleFilter {
* SQL expression to use in the rule filter.
* Defaults to creating a true filter if none specified
*/
sqlExpression?: string;
sqlExpression: string;
/**
* SQL parameters to the SQL expression in the rule filter.
@ -189,14 +192,17 @@ export class RuleResourceSerializer implements AtomXmlSerializer {
resource.Filter = {
CorrelationId: correlationFilter.correlationId,
Label: correlationFilter.label,
Label: correlationFilter.subject,
To: correlationFilter.to,
ReplyTo: correlationFilter.replyTo,
ReplyToSessionId: correlationFilter.replyToSessionId,
ContentType: correlationFilter.contentType,
SessionId: correlationFilter.sessionId,
MessageId: correlationFilter.messageId,
Properties: buildInternalRawKeyValuePairs(correlationFilter.properties, "userProperties")
Properties: buildInternalRawKeyValuePairs(
correlationFilter.applicationProperties,
"applicationProperties"
)
};
resource.Filter[Constants.XML_METADATA_MARKER] = {
"p4:type": "CorrelationFilter",
@ -300,7 +306,7 @@ const keyValuePairXMLTag = "KeyValueOfstringanyType";
*/
function getKeyValuePairsOrUndefined(
value: any,
attribute: "UserProperties" | "SQLParameters"
attribute: "ApplicationProperties" | "SQLParameters"
): { [key: string]: any } | undefined {
if (!value) {
return undefined;
@ -353,7 +359,7 @@ function getKeyValuePairsOrUndefined(
*/
export function buildInternalRawKeyValuePairs(
parameters: { [key: string]: any } | undefined,
attribute: "userProperties" | "sqlParameters"
attribute: "applicationProperties" | "sqlParameters"
): InternalRawKeyValuePairs | undefined {
if (parameters == undefined) {
return undefined;

Просмотреть файл

@ -180,7 +180,7 @@ export interface ServiceBusMessage {
* application to indicate the purpose of the message to the receiver in a standardized. fashion,
* similar to an email subject line. The mapped AMQP property is "subject".
*/
label?: string;
subject?: string;
/**
* @property The "to" address. This property is reserved for future use in routing
* scenarios and presently ignored by the broker itself. Applications can use this value in
@ -209,7 +209,12 @@ export interface ServiceBusMessage {
* @property The application specific properties which can be
* used for custom message metadata.
*/
properties?: { [key: string]: number | boolean | string | Date };
applicationProperties?: { [key: string]: number | boolean | string | Date };
/**
* @property The identity of the user producing the message.
*/
userId?: string;
}
/**
@ -349,7 +354,7 @@ export function getMessagePropertyTypeMismatchError(msg: ServiceBusMessage): Err
return new TypeError("The property 'contentType' on the message must be of type 'string'");
}
if (msg.label != null && typeof msg.label !== "string") {
if (msg.subject != null && typeof msg.subject !== "string") {
return new TypeError("The property 'label' on the message must be of type 'string'");
}
@ -407,8 +412,8 @@ export function toAmqpMessage(msg: ServiceBusMessage): AmqpMessage {
body: msg.body,
message_annotations: {}
};
if (msg.properties != null) {
amqpMsg.application_properties = msg.properties;
if (msg.applicationProperties != null) {
amqpMsg.application_properties = msg.applicationProperties;
}
if (msg.contentType != null) {
amqpMsg.content_type = msg.contentType;
@ -427,8 +432,8 @@ export function toAmqpMessage(msg: ServiceBusMessage): AmqpMessage {
if (msg.to != null) {
amqpMsg.to = msg.to;
}
if (msg.label != null) {
amqpMsg.subject = msg.label;
if (msg.subject != null) {
amqpMsg.subject = msg.subject;
}
if (msg.messageId != null) {
if (typeof msg.messageId === "string" && msg.messageId.length > Constants.maxMessageIdLength) {
@ -472,6 +477,11 @@ export function toAmqpMessage(msg: ServiceBusMessage): AmqpMessage {
if (msg.scheduledEnqueueTimeUtc != null) {
amqpMsg.message_annotations![Constants.scheduledEnqueueTime] = msg.scheduledEnqueueTimeUtc;
}
if (msg.userId != null) {
amqpMsg.user_id = msg.userId;
}
logger.verbose("SBMessage to AmqpMessage: %O", amqpMsg);
return amqpMsg;
}
@ -704,7 +714,7 @@ export function fromAmqpMessage(
};
if (msg.application_properties != null) {
sbmsg.properties = msg.application_properties;
sbmsg.applicationProperties = msg.application_properties;
}
if (msg.content_type != null) {
sbmsg.contentType = msg.content_type;
@ -722,7 +732,7 @@ export function fromAmqpMessage(
sbmsg.timeToLive = msg.ttl;
}
if (msg.subject != null) {
sbmsg.label = msg.subject;
sbmsg.subject = msg.subject;
}
if (msg.message_id != null) {
sbmsg.messageId = msg.message_id;
@ -774,6 +784,10 @@ export function fromAmqpMessage(
props.expiresAtUtc = new Date(props.enqueuedTimeUtc.getTime() + msg.ttl!);
}
if (msg.user_id != null) {
sbmsg.userId = msg.user_id;
}
const rcvdsbmsg: ServiceBusReceivedMessage = {
_amqpAnnotatedMessage: toAmqpAnnotatedMessage(msg),
_delivery: delivery,
@ -792,8 +806,8 @@ export function fromAmqpMessage(
: undefined,
...sbmsg,
...props,
deadLetterReason: sbmsg.properties?.DeadLetterReason,
deadLetterErrorDescription: sbmsg.properties?.DeadLetterErrorDescription
deadLetterReason: sbmsg.applicationProperties?.DeadLetterReason,
deadLetterErrorDescription: sbmsg.applicationProperties?.DeadLetterErrorDescription
};
logger.verbose("AmqpMessage to ReceivedSBMessage: %O", rcvdsbmsg);
@ -846,7 +860,7 @@ export class ServiceBusMessageImpl implements ServiceBusReceivedMessageWithLock
/**
* @property The application specific properties.
*/
properties?: { [key: string]: any };
applicationProperties?: { [key: string]: any };
/**
* @property The message identifier is an
* application-defined value that uniquely identifies the message and its payload. The identifier
@ -918,7 +932,7 @@ export class ServiceBusMessageImpl implements ServiceBusReceivedMessageWithLock
* application to indicate the purpose of the message to the receiver in a standardized. fashion,
* similar to an email subject line. The mapped AMQP property is "subject".
*/
label?: string;
subject?: string;
/**
* @property The "to" address. This property is reserved for future use in routing
* scenarios and presently ignored by the broker itself. Applications can use this value in
@ -1177,7 +1191,7 @@ export class ServiceBusMessageImpl implements ServiceBusReceivedMessageWithLock
body: this.body,
contentType: this.contentType,
correlationId: this.correlationId,
label: this.label,
subject: this.subject,
messageId: this.messageId,
partitionKey: this.partitionKey,
replyTo: this.replyTo,
@ -1186,7 +1200,7 @@ export class ServiceBusMessageImpl implements ServiceBusReceivedMessageWithLock
sessionId: this.sessionId,
timeToLive: this.timeToLive,
to: this.to,
properties: this.properties,
applicationProperties: this.applicationProperties,
viaPartitionKey: this.viaPartitionKey
};

Просмотреть файл

@ -251,7 +251,7 @@ export class ServiceBusMessageBatchImpl implements ServiceBusMessageBatch {
// check if the event has already been instrumented
const previouslyInstrumented = Boolean(
message.properties && message.properties[TRACEPARENT_PROPERTY]
message.applicationProperties && message.applicationProperties[TRACEPARENT_PROPERTY]
);
let spanContext: SpanContext | undefined;
if (!previouslyInstrumented) {

Просмотреть файл

@ -9,7 +9,7 @@ import chaiAsPromised from "chai-as-promised";
import chaiExclude from "chai-exclude";
import * as dotenv from "dotenv";
import { CreateQueueOptions } from "../src/serializers/queueResourceSerializer";
import { RuleProperties } from "../src/serializers/ruleResourceSerializer";
import { RuleProperties, CreateRuleOptions } from "../src/serializers/ruleResourceSerializer";
import { CreateSubscriptionOptions } from "../src/serializers/subscriptionResourceSerializer";
import { CreateTopicOptions } from "../src/serializers/topicResourceSerializer";
import { ServiceBusAdministrationClient } from "../src/serviceBusAtomManagementClient";
@ -1694,7 +1694,11 @@ describe("Atom management - Authentication", function(): void {
});
// Rule tests
[
const createRuleTests: {
testCaseTitle: string;
input: Omit<CreateRuleOptions, "name"> | undefined;
output: RuleProperties;
}[] = [
{
testCaseTitle: "Undefined rule options",
input: undefined,
@ -1736,7 +1740,7 @@ describe("Atom management - Authentication", function(): void {
input: {
filter: {
correlationId: "abcd",
properties: {
applicationProperties: {
randomState: "WA"
}
},
@ -1746,13 +1750,13 @@ describe("Atom management - Authentication", function(): void {
filter: {
correlationId: "abcd",
contentType: "",
label: "",
subject: "",
messageId: "",
replyTo: "",
replyToSessionId: "",
sessionId: "",
to: "",
properties: {
applicationProperties: {
randomState: "WA"
}
},
@ -1768,7 +1772,7 @@ describe("Atom management - Authentication", function(): void {
input: {
filter: {
correlationId: "abcd",
properties: {
applicationProperties: {
randomState: "WA",
randomCountry: "US",
randomCount: 25,
@ -1782,13 +1786,13 @@ describe("Atom management - Authentication", function(): void {
filter: {
correlationId: "abcd",
contentType: "",
label: "",
subject: "",
messageId: "",
replyTo: "",
replyToSessionId: "",
sessionId: "",
to: "",
properties: {
applicationProperties: {
randomState: "WA",
randomCountry: "US",
randomCount: 25,
@ -1803,7 +1807,8 @@ describe("Atom management - Authentication", function(): void {
name: managementRule1
}
}
].forEach((testCase) => {
];
createRuleTests.forEach((testCase) => {
describe(`createRule() using different variations to the input parameter "ruleOptions"`, function(): void {
beforeEach(async () => {
await recreateTopic(managementTopic1);
@ -2315,13 +2320,13 @@ describe("Atom management - Authentication", function(): void {
filter: {
correlationId: "defg",
contentType: "",
label: "",
subject: "",
messageId: "",
replyTo: "",
replyToSessionId: "",
sessionId: "",
to: "",
properties: undefined
applicationProperties: undefined
},
action: {
sqlExpression: "SET sys.label='RED'",
@ -2410,7 +2415,7 @@ async function createEntity(
queueOptions?: Omit<CreateQueueOptions, "name">,
topicOptions?: Omit<CreateTopicOptions, "name">,
subscriptionOptions?: Omit<CreateSubscriptionOptions, "topicName" | "subscriptionName">,
ruleOptions?: Omit<RuleProperties, "name">
ruleOptions?: Omit<CreateRuleOptions, "name">
): Promise<any> {
if (!overrideOptions) {
if (queueOptions == undefined) {

Просмотреть файл

@ -565,13 +565,13 @@ describe("ATOM Serializers", () => {
input: {
filter: {
correlationId: "abcd",
properties: {
applicationProperties: {
message: ["hello"]
}
}
},
output: {
testErrorMessage: `Unsupported type for the value in the userProperties for the key 'message'`,
testErrorMessage: `Unsupported type for the value in the applicationProperties for the key 'message'`,
testErrorType: Error
}
},
@ -581,13 +581,13 @@ describe("ATOM Serializers", () => {
input: {
filter: {
correlationId: "abcd",
properties: {
applicationProperties: {
message: {}
}
}
},
output: {
testErrorMessage: `Unsupported type for the value in the userProperties for the key 'message'`,
testErrorMessage: `Unsupported type for the value in the applicationProperties for the key 'message'`,
testErrorType: Error
}
},
@ -597,13 +597,13 @@ describe("ATOM Serializers", () => {
input: {
filter: {
correlationId: "abcd",
properties: {
applicationProperties: {
message: undefined
}
}
},
output: {
testErrorMessage: `Unsupported type for the value in the userProperties for the key 'message'`,
testErrorMessage: `Unsupported type for the value in the applicationProperties for the key 'message'`,
testErrorType: Error
}
},
@ -613,11 +613,11 @@ describe("ATOM Serializers", () => {
input: {
filter: {
correlationId: "abcd",
properties: 123
applicationProperties: 123
}
},
output: {
testErrorMessage: `Unsupported value for the userProperties 123, expected a JSON object with key-value pairs.`,
testErrorMessage: `Unsupported value for the applicationProperties 123, expected a JSON object with key-value pairs.`,
testErrorType: Error
}
},
@ -627,11 +627,11 @@ describe("ATOM Serializers", () => {
input: {
filter: {
correlationId: "abcd",
properties: "abcd"
applicationProperties: "abcd"
}
},
output: {
testErrorMessage: `Unsupported value for the userProperties "abcd", expected a JSON object with key-value pairs.`,
testErrorMessage: `Unsupported value for the applicationProperties "abcd", expected a JSON object with key-value pairs.`,
testErrorType: Error
}
},
@ -641,11 +641,11 @@ describe("ATOM Serializers", () => {
input: {
filter: {
correlationId: "abcd",
properties: ["abcd"]
applicationProperties: ["abcd"]
}
},
output: {
testErrorMessage: `Unsupported value for the userProperties ["abcd"], expected a JSON object with key-value pairs.`,
testErrorMessage: `Unsupported value for the applicationProperties ["abcd"], expected a JSON object with key-value pairs.`,
testErrorType: Error
}
},
@ -655,11 +655,11 @@ describe("ATOM Serializers", () => {
input: {
filter: {
correlationId: "abcd",
properties: {}
applicationProperties: {}
}
},
output: {
testErrorMessage: `Unsupported value for the userProperties {}, expected a JSON object with key-value pairs.`,
testErrorMessage: `Unsupported value for the applicationProperties {}, expected a JSON object with key-value pairs.`,
testErrorType: Error
}
}

Просмотреть файл

@ -204,6 +204,6 @@ describe("ServiceBusMessageImpl AmqpAnnotations unit tests", () => {
sbMessage._amqpAnnotatedMessage.properties?.replyToGroupId,
sbMessage.replyToSessionId
);
assert.equal(sbMessage._amqpAnnotatedMessage.properties?.subject, sbMessage.label);
assert.equal(sbMessage._amqpAnnotatedMessage.properties?.subject, sbMessage.subject);
});
});

Просмотреть файл

@ -66,12 +66,12 @@ describe("Tracing tests", () => {
br["_receiveMessagesImpl"] = async () => {
return ([
{
properties: {
applicationProperties: {
"Diagnostic-Id": "diagnostic id 1"
}
},
{
properties: {
applicationProperties: {
"Diagnostic-Id": "diagnostic id 2"
}
}
@ -88,14 +88,15 @@ describe("Tracing tests", () => {
assert.isTrue(createSpanStub.calledOnce, "create span was called");
const [messages, , , options] = createSpanStub.args[0];
assert.isTrue(
Array.isArray(messages),
"only expect one call to the create a span (it can handle multiple messages)"
);
assert.deepEqual(
(messages as ServiceBusReceivedMessage[]).map((m) => m.properties!["Diagnostic-Id"]),
(messages as ServiceBusReceivedMessage[]).map(
(m) => m.applicationProperties!["Diagnostic-Id"]
),
["diagnostic id 1", "diagnostic id 2"]
);
@ -125,7 +126,7 @@ describe("Tracing tests", () => {
receiver.subscribe(
{
processMessage: async (msg) => {
if (msg.properties!["Diagnostic-Id"] === "should throw") {
if (msg.applicationProperties!["Diagnostic-Id"] === "should throw") {
throw new Error("This message failed when we tried to process it");
}
},
@ -140,7 +141,7 @@ describe("Tracing tests", () => {
try {
await processMessage!(({
properties: {
applicationProperties: {
[TRACEPARENT_PROPERTY]: "should throw"
}
} as any) as ServiceBusMessageImpl);
@ -155,7 +156,7 @@ describe("Tracing tests", () => {
}
await processMessage!(({
properties: {
applicationProperties: {
[TRACEPARENT_PROPERTY]: "should NOT throw"
}
} as any) as ServiceBusMessageImpl);
@ -182,7 +183,7 @@ describe("Tracing tests", () => {
receiver.subscribe(
{
processMessage: async (msg) => {
if (msg.properties!["Diagnostic-Id"] === "should throw") {
if (msg.applicationProperties!["Diagnostic-Id"] === "should throw") {
throw new Error("This message failed when we tried to process it");
}
},
@ -197,7 +198,7 @@ describe("Tracing tests", () => {
try {
await processMessage!(({
properties: {
applicationProperties: {
[TRACEPARENT_PROPERTY]: "should throw"
}
} as any) as ServiceBusMessageImpl);
@ -211,7 +212,7 @@ describe("Tracing tests", () => {
}
await processMessage!(({
properties: {
applicationProperties: {
[TRACEPARENT_PROPERTY]: "should NOT throw"
}
} as any) as ServiceBusMessageImpl);
@ -327,7 +328,7 @@ describe("Tracing tests", () => {
const receivedMessages: ServiceBusMessage[] = [
instrumentServiceBusMessage({ ...requiredMessageProperties }, firstEvent),
{ properties: {}, ...requiredMessageProperties }, // no diagnostic ID means it gets skipped
{ applicationProperties: {}, ...requiredMessageProperties }, // no diagnostic ID means it gets skipped
instrumentServiceBusMessage({ ...requiredMessageProperties }, thirdEvent)
];

Просмотреть файл

@ -332,7 +332,7 @@ describe("utils", () => {
const receivedMessage: ServiceBusReceivedMessage = {
body: "This is a test.",
enqueuedTimeUtc: new Date(),
properties: {
applicationProperties: {
[TRACEPARENT_PROPERTY]: `00-${traceId}-${spanId}-${flags}`
},
_amqpAnnotatedMessage: { body: "This is a test." }
@ -357,7 +357,7 @@ describe("utils", () => {
const receivedMessage: ServiceBusReceivedMessage = {
body: "This is a test.",
enqueuedTimeUtc: new Date(),
properties: {
applicationProperties: {
[TRACEPARENT_PROPERTY]: `99-${traceId}-${spanId}-${flags}`
},
_amqpAnnotatedMessage: { body: "This is a test." }

Просмотреть файл

@ -160,7 +160,7 @@ describe("dead lettering", () => {
const reason = deadLetterMessages[0].deadLetterReason;
const description = deadLetterMessages[0].deadLetterErrorDescription;
const customProperty = deadLetterMessages[0]!.properties!["customProperty"];
const customProperty = deadLetterMessages[0]!.applicationProperties!["customProperty"];
should.equal(reason, expected.reason);
should.equal(description, expected.description);
@ -285,7 +285,7 @@ describe("abandoning", () => {
) {
should.exist(abandonedMessage);
const customProperty = abandonedMessage.properties!["customProperty"];
const customProperty = abandonedMessage.applicationProperties!["customProperty"];
should.equal(customProperty, expected.customProperty);
}
@ -401,7 +401,7 @@ describe("deferring", () => {
should.exist(deferredMessage);
const customProperty = deferredMessage!.properties!["customProperty"];
const customProperty = deferredMessage!.applicationProperties!["customProperty"];
should.equal(customProperty, expected.customProperty);
}

Просмотреть файл

@ -410,7 +410,7 @@ describe("ServiceBusMessage validations", function(): void {
title: "contentType is of invalid type"
},
{
message: { body: "", label: 1 as any },
message: { body: "", subject: 1 as any },
expectedErrorMessage: "The property 'label' on the message must be of type 'string'",
title: "label is of invalid type"
},
@ -604,7 +604,7 @@ describe("Tracing for send", function(): void {
{ name: "Albert" },
{
name: "Marie",
properties: {
applicationProperties: {
[TRACEPARENT_PROPERTY]: "foo"
}
}
@ -614,7 +614,7 @@ describe("Tracing for send", function(): void {
for (let i = 0; i < 2; i++) {
batch.tryAdd(
{ body: `${list[i].name}`, properties: list[i].properties },
{ body: `${list[i].name}`, applicationProperties: list[i].applicationProperties },
{ parentSpan: rootSpan }
);
}
@ -777,7 +777,7 @@ describe("Tracing for send", function(): void {
for (let i = 0; i < 5; i++) {
messages.push({ body: `multiple messages - manual trace propgation: ${i}` });
}
messages[0].properties = { [TRACEPARENT_PROPERTY]: "foo" };
messages[0].applicationProperties = { [TRACEPARENT_PROPERTY]: "foo" };
await sender.sendMessages(messages, {
tracingOptions: {
spanOptions: {

Просмотреть файл

@ -21,16 +21,17 @@ export class TestMessage {
contentType: `content type ${randomTag}`,
correlationId: `correlation id ${randomTag}`,
timeToLive: 60 * 60 * 24,
label: `label ${randomTag}`,
subject: `label ${randomTag}`,
to: `to ${randomTag}`,
replyTo: `reply to ${randomTag}`,
scheduledEnqueueTimeUtc: new Date(),
properties: {
applicationProperties: {
propOne: 1,
propTwo: "two",
propThree: true,
propFour: Date()
}
},
userId: `${randomTag} userId`
};
}
@ -43,17 +44,18 @@ export class TestMessage {
contentType: `content type ${randomNumber}`,
correlationId: `correlation id ${randomNumber}`,
timeToLive: 60 * 60 * 24,
label: `label ${randomNumber}`,
subject: `label ${randomNumber}`,
to: `to ${randomNumber}`,
replyTo: `reply to ${randomNumber}`,
scheduledEnqueueTimeUtc: new Date(),
properties: {
applicationProperties: {
propOne: 1,
propTwo: "two",
propThree: true
},
sessionId: TestMessage.sessionId,
replyToSessionId: "some-other-session-id"
replyToSessionId: "some-other-session-id",
userId: `${randomNumber} userId`
};
}
@ -67,13 +69,13 @@ export class TestMessage {
useSessions?: boolean,
usePartitions?: boolean
): void {
if (sent.properties) {
if (!received.properties) {
if (sent.applicationProperties) {
if (!received.applicationProperties) {
chai.assert.fail("Received message doesnt have any user properties");
return;
}
const expectedUserProperties = sent.properties;
const receivedUserProperties = received.properties;
const expectedUserProperties = sent.applicationProperties;
const receivedUserProperties = received.applicationProperties;
Object.keys(expectedUserProperties).forEach((key) => {
chai.assert.equal(
receivedUserProperties[key],
@ -125,6 +127,8 @@ export class TestMessage {
`Unexpected partitionKey in received msg`
);
}
chai.assert.equal(received.userId, sent.userId, "Unexpected userId in received msg");
}
}