Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function main(): Promise {
await authenticate(ehConnectionConfig.getReceiverAudience("0"));
const receiverName = "receiver-1";
// Get messages from the past hour
const filterClause = `amqp.annotation.x-opt-enqueued-time > '${Date.now() - 3600 * 1000}'`;
const receiverAddress = ehConnectionConfig.getReceiverAddress("0");
const receiverOptions: ReceiverOptions = {
name: receiverName,
source: {
address: receiverAddress,
filter: {
"apache.org:selector-filter:string": types.wrap_described(filterClause, 0x468c00000004)
}
},
onSessionError: (context: EventContext) => {
const sessionError = context.session && context.session.error;
if (sessionError) {
console.log(
">>>>> [%s] An error occurred for session of receiver '%s': %O.",
connectionContext.connection.id,
receiverName,
sessionError
);
}
}
};
const receiver: Receiver = await connectionContext.connection.createReceiver(receiverOptions);
async function main(): Promise {
await authenticate(`${connectionConfig.endpoint}${path}`, false);
const receiverName = "receiver-1";
const filterClause = `amqp.annotation.x-opt-enqueued-time > '${Date.now() - 3600 * 1000}'`; // Get messages from the past hour
const receiverAddress = `${path}/ConsumerGroups/$default/Partitions/0`; // For ServiceBus ""
const receiverOptions: ReceiverOptions = {
name: receiverName,
source: {
address: receiverAddress,
filter: {
// May not be required for ServiceBus. The current example is for EventHubs.
"apache.org:selector-filter:string": types.wrap_described(filterClause, 0x468c00000004)
}
},
onSessionError: (context: EventContext) => {
const sessionError = context.session && context.session.error;
if (sessionError) {
console.log(
">>>>> [%s] An error occurred for session of receiver '%s': %O.",
connectionContext.connection.id,
receiverName,
sessionError
);
}
}
};
const receiver: Receiver = await connectionContext.connection.createReceiver(receiverOptions);
async function main(): Promise {
await authenticate(ehConnectionConfig.getReceiverAudience("0"));
const receiverName = "receiver-1";
// Get messages from the past hour
const filterClause = `amqp.annotation.x-opt-enqueued-time > '${Date.now() -
3600 * 1000}'`;
const receiverAddress = ehConnectionConfig.getReceiverAddress("0");
const receiverOptions: ReceiverOptions = {
name: receiverName,
source: {
address: receiverAddress,
filter: {
"apache.org:selector-filter:string": types.wrap_described(
filterClause,
0x468c00000004
)
}
},
onSessionError: (context: EventContext) => {
const sessionError = context.session && context.session.error;
if (sessionError) {
console.log(
">>>>> [%s] An error occurred for session of receiver '%s': %O.",
connectionContext.connection.id,
receiverName,
sessionError
);
}
}
rcvrOptions.properties = {
[Constants.attachEpoch]: types.wrap_long(this.ownerLevel)
};
}
if (this.options.trackLastEnqueuedEventProperties) {
rcvrOptions.desired_capabilities = Constants.enableReceiverRuntimeMetricName;
}
const eventPosition = options.eventPosition || this.eventPosition;
if (eventPosition) {
// Set filter on the receiver if event position is specified.
const filterClause = getEventPositionFilter(eventPosition);
if (filterClause) {
(rcvrOptions.source as any).filter = {
"apache.org:selector-filter:string": types.wrap_described(filterClause, 0x468c00000004)
};
}
}
return rcvrOptions;
}
}
rcvrOptions.properties[Constants.attachEpoch] = types.wrap_long(this.epoch);
}
if (this.identifier) {
if (!rcvrOptions.properties) rcvrOptions.properties = {};
rcvrOptions.properties[Constants.receiverIdentifierName] = this.identifier;
}
if (this.receiverRuntimeMetricEnabled) {
rcvrOptions.desired_capabilities = Constants.enableReceiverRuntimeMetricName;
}
const eventPosition = options.eventPosition || this.options.eventPosition;
if (eventPosition) {
// Set filter on the receiver if event position is specified.
const filterClause = eventPosition.getExpression();
if (filterClause) {
(rcvrOptions.source as any).filter = {
"apache.org:selector-filter:string": types.wrap_described(filterClause, 0x468c00000004)
};
}
}
return rcvrOptions;
}
}