-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiple fixes and updates to rhea-promise (#44)
* Added id to the session object and improved log statements * add closeSync flavored methods to Link and Session * simplify the closeSync version. * rectify the example * Handle connection getting disconnected while closing the link, session or connection itself. * handle connection disconnects while creating a session, sender or receiver. * update readme * Added asynchronous sender * refactor code * updated changelog * addressed review feedback * remove closeSync() * address review feedback * Awaitable Sender * fix casing * Log the protocol error since rhea does not pass that error to the context in disconnected event handler * improve logs * updates as per code review * improved log statement and updated min. version of rhea to 1.0.8
- Loading branch information
1 parent
6f1a916
commit 3fdbbd5
Showing
19 changed files
with
847 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the Apache License. See License in the project root for license information. | ||
|
||
import { | ||
Connection, | ||
Message, | ||
ConnectionOptions, | ||
Delivery, | ||
AwaitableSenderOptions, | ||
AwaitableSender | ||
} from "../lib"; | ||
|
||
import * as dotenv from "dotenv"; // Optional for loading environment configuration from a .env (config) file | ||
dotenv.config(); | ||
|
||
const host = process.env.AMQP_HOST || "host"; | ||
const username = process.env.AMQP_USERNAME || "sharedAccessKeyName"; | ||
const password = process.env.AMQP_PASSWORD || "sharedAccessKeyValue"; | ||
const port = parseInt(process.env.AMQP_PORT || "5671"); | ||
const senderAddress = process.env.SENDER_ADDRESS || "address"; | ||
|
||
async function main(): Promise<void> { | ||
const connectionOptions: ConnectionOptions = { | ||
transport: "tls", | ||
host: host, | ||
hostname: host, | ||
username: username, | ||
password: password, | ||
port: port, | ||
reconnect: false | ||
}; | ||
const connection: Connection = new Connection(connectionOptions); | ||
const senderName = "sender-1"; | ||
const senderOptions: AwaitableSenderOptions = { | ||
name: senderName, | ||
target: { | ||
address: senderAddress | ||
}, | ||
sendTimeoutInSeconds: 10 | ||
}; | ||
|
||
await connection.open(); | ||
const sender: AwaitableSender = await connection.createAwaitableSender( | ||
senderOptions | ||
); | ||
|
||
for (let i = 0; i < 10; i++) { | ||
const message: Message = { | ||
body: `Hello World - ${i}`, | ||
message_id: i | ||
}; | ||
// Please, note that we are awaiting on sender.send() to complete. | ||
// You will notice that `delivery.settled` will be `true`, irrespective of whether the promise resolves or rejects. | ||
const delivery: Delivery = await sender.send(message); | ||
console.log( | ||
"[%s] await sendMessage -> Delivery id: %d, settled: %s", | ||
connection.id, | ||
delivery.id, | ||
delivery.settled | ||
); | ||
} | ||
|
||
await sender.close(); | ||
await connection.close(); | ||
} | ||
|
||
main().catch((err) => console.log(err)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.