Skip to content

Commit

Permalink
[core-amqp] remove v1 samples and snippets from README (Azure#12454)
Browse files Browse the repository at this point in the history
* [core-amqp] remove v1 samples and snippets from README

* [core-amqp] add readme exception
  • Loading branch information
chradek authored Nov 10, 2020
1 parent 3d76cc1 commit 121ed88
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 532 deletions.
1 change: 1 addition & 0 deletions eng/.docsettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ known_content_issues:
- ["sdk/cognitiveservices/cognitiveservices-visualsearch/README.md",  "#1583"]
- ["sdk/cognitiveservices/cognitiveservices-websearch/README.md",  "#1583"]
- ["sdk/core/abort-controller/README.md",  "#1583"]
- ["sdk/core/core-amqp/README.md",  "#1583"]
- ["sdk/core/core-auth/README.md",  "#1583"]
- ["sdk/core/core-tracing/README.md",  "#1583"]
- ["sdk/core/logger/README.md",  "#1583"]
Expand Down
153 changes: 0 additions & 153 deletions sdk/core/core-amqp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,164 +14,15 @@ Install this library using npm as follows:
npm install @azure/core-amqp
```

**Note**: [`rhea-promise`](https://github.com/amqp/rhea-promise) is a peer dependency. You need to explicitly install this library as a dependency
in your application.

## Key concepts

Some of the key features of Azure Core AMQP library are:

- [Claims based Authorization](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-amqp-protocol-guide#claims-based-authorization)
- Request-Response link for [sending request and receiving response over AMQP](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-amqp-protocol-guide#amqp-management)
- A Data Transformer class to encode given data to an AMQP message and decode a given AMQP message. Useful for sending and receiving messages that are not of type Buffer.
- Error translation of AMQP error codes along with errors specific to Azure Service Bus and Azure Event Hubs.
- RetryPolicy for retrying a given operation if a retryable error was encountered.

## Examples

[Claims Based Authorization](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-amqp-protocol-guide#claims-based-authorization)
need to be done for every AMQP link that your application creates. The claims also has to be renewed periodically.
For more details on CBS, please see the [CBS Specification](https://www.oasis-open.org/committees/download.php/62097/amqp-cbs-v1.0-wd05.doc).

In the below examples, we use the Shared Key details present in the connection string to create a SAS token.
This token is then used to make a request on the \$cbs link to carry out Claims Based Authorization for a link to the given entity
in Azure Service Bus or Azure Event Hubs.

The examples below expect a connection string to a Azure Service Bus or Azure Event Hubs instance.
The entity path refers to an Event Hub name in case of Azure Event Hubs and a queue or a topic name
in case of Azure Service Bus.

## Create a sender link

In the below example, we first create a `ConnectionContext` which is used to carry out the claims
based authorization. Then, we create a sender link using the `ConnectionContext.connection` to
send a message.

```js
async function main() {
const connectionConfig = ConnectionConfig.create(
"your-connection-string-with-shared-key",
"entity-path"
);
const connectionContext = ConnectionContextBase.create({
config: connectionConfig,
connectionProperties: {
product: "product",
userAgent: "/user-agent",
version: "0.0.0"
}
});

// Carry out the Claims Based Authorization
await connectionContext.cbsSession.init();
const token = await connectionContext.tokenCredential.getToken(audience);
await connectionContext.cbsSession.negotiateClaim(audience, token, TokenType.CbsTokenTypeSas);

// Create a sender
const senderName = "your-sender-name";
const senderOptions = {
name: senderName,
target: {
// For an EventHub Sender bound to a partition, the address will be "<EventHubName>/Partitions/<PartitionId>"
address: `${connectionConfig.entityPath}`
},
onError: (context) => {
const senderError = context.sender && context.sender.error;
if (senderError) {
console.log("An error occurred for sender '%s': %O.", senderName, senderError);
}
},
onSessionError: (context) => {
const sessionError = context.session && context.session.error;
if (sessionError) {
console.log("An error occurred for session of sender '%s': %O.", senderName, sessionError);
}
}
};
const sender = await connectionContext.connection.createSender(senderOptions);

// Send a message
const delivery = await sender.send({ body: "your-message-body" });

await sender.close();
await connectionContext.connection.close();
}

main().catch((err) => console.log(err));
```

## Create a receiver link

In the below example, we first create a `ConnectionContext` which is used to carry out the claims
based authorization. Then, we create a receiver link using the `ConnectionContext.connection` to
receive messages for 30 seconds.

```js
async function main() {
const connectionConfig = ConnectionConfig.create(
"your-connection-string-with-shared-key",
"entity-path"
);
const connectionContext = ConnectionContextBase.create({
config: connectionConfig,
connectionProperties: {
product: "product",
userAgent: "/user-agent",
version: "0.0.0"
}
});

// Carry out the Claims Based Authorization
await connectionContext.cbsSession.init();
const token = await connectionContext.tokenCredential.getToken(audience);
await connectionContext.cbsSession.negotiateClaim(audience, token, TokenType.CbsTokenTypeSas);

// Create a receiver
const receiverName = "your-receiver-name";
const filterClause = `amqp.annotation.x-opt-enqueued-time > '${Date.now() - 3600 * 1000}'`; // Get messages from the past hour
const receiverAddress = `${connectionConfig.entityPath}/ConsumerGroups/$default/Partitions/0`; // For ServiceBus "<QueueName>"
const 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)
}
},
onError: (context) => {
const receiverError = context.receiver && context.receiver.error;
if (receiverError) {
console.log("An error occurred for receiver '%s': %O.", receiverName, receiverError);
}
},
onMessage: (context) => {
console.log("Received message: %O", context.message);
},
onSessionError: (context) => {
const sessionError = context.session && context.session.error;
if (sessionError) {
console.log(
"An error occurred for session of receiver '%s': %O.",
receiverName,
sessionError
);
}
}
};
const receiver = await connectionContext.connection.createReceiver(receiverOptions);

// sleeping for 30 seconds to let the receiver receive messages
await new Promise((r) => setTimeout(r, 30000));

// Close the receiver to stop receiving messages
await receiver.close();
await connectionContext.connection.close();
}

main().catch((err) => console.log(err));
```

## Troubleshooting

The core-amqp library depends on the [rhea-promise](https://github.com/amqp/rhea-promise) library for managing connections, and for sending and receiving events over the [AMQP](https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-complete-v1.0-os.pdf) protocol.
Expand Down Expand Up @@ -243,10 +94,6 @@ export DEBUG=azure:core-amqp:(error|warning),rhea-promise:error,rhea:events,rhea
node your-test-script.js &> out.log
```

# Next steps

Please take a look at the [samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/core-amqp/samples) directory for detailed samples.

# Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-amqp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
],
"scripts": {
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:samples": "cd samples && tsc -p .",
"build:samples": "echo skipped",
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
"build:types": "downlevel-dts types/latest types/3.1",
"build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local && npm run build:types",
Expand Down
78 changes: 0 additions & 78 deletions sdk/core/core-amqp/samples/cbsAuthUsingAad.ts

This file was deleted.

87 changes: 0 additions & 87 deletions sdk/core/core-amqp/samples/cbsAuthUsingSas.ts

This file was deleted.

Loading

0 comments on commit 121ed88

Please sign in to comment.