You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sdk/eventhub/event-processor-host/README.md
+58-22Lines changed: 58 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,56 +1,72 @@
1
-
@azure/event-processor-host
2
-
================
1
+
# @azure/event-processor-host
2
+
3
+
> Please note, a newer package [@azure/event-hubs](https://www.npmjs.com/package/@azure/event-hubs) is available as of January, 2020. While this package will continue to receive critical bug fixes, we strongly encourage you to upgrade. See the [migration guide](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-hubs/migrationguide.md) for more details.
3
4
4
5
Azure Event Processor Host helps you efficiently receive events from an EventHub. It will create EventHub Receivers
5
6
across all the partitions in the provided consumer group of an EventHub and provide you messages received across
6
7
all the partitions. It will checkpoint metadata about the received messages at regular interval in an
7
8
Azure Storage Blob. This makes it easy to continue receiving messages from where you left at a later time.
- More information about Azure Event Processor Host can be found over [here](https://docs.microsoft.com/azure/event-hubs/event-hubs-event-processor-host).
13
15
- General overview of how the Event Processor Host SDK works internally can be found over [here](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-processor-host/overview.md).
14
16
15
-
## Pre-requisite ##
16
-
-**Node.js version: 6.x or higher.**
17
+
## Pre-requisite
18
+
19
+
-**Node.js version: 6.x or higher.**
17
20
- We would **still encourage you** to install the latest available LTS version at any given time from https://nodejs.org. **It is a good practice to always install the latest available LTS version of node.js.**
18
21
- Installing node.js on **Windows or macOS** is very simple with available installers on the [node.js website](https://nodejs.org). If you are using a **linux based OS**, then you can find easy to follow, one step installation instructions over [here](https://nodejs.org/en/download/package-manager/).
19
22
20
-
## Installation ##
23
+
## Installation
24
+
21
25
```bash
22
26
npm install @azure/event-processor-host
23
27
```
24
-
## IDE ##
25
-
This sdk has been developed in [TypeScript](https://typescriptlang.org) and has good source code documentation. It is highly recommended to use [vscode](https://code.visualstudio.com)
28
+
29
+
## IDE
30
+
31
+
This sdk has been developed in [TypeScript](https://typescriptlang.org) and has good source code documentation. It is highly recommended to use [vscode](https://code.visualstudio.com)
26
32
or any other IDE that provides better intellisense and exposes the full power of source code documentation.
27
33
28
-
## Debug logs ##
34
+
## Debug logs
29
35
30
36
You can set the following environment variable to get the debug logs.
31
37
32
38
- Getting debug logs **only** from the Event Processor Host SDK
39
+
33
40
```bash
34
41
export DEBUG=azure:eph*
35
42
```
43
+
36
44
- Getting debug logs from the Event Processor Host SDK **and** the protocol level library.
45
+
37
46
```bash
38
47
export DEBUG=azure:eph*,rhea*
39
48
```
49
+
40
50
- Getting debug logs from the **Event Processor Host SDK, the Event Hub SDK and the protocol level library.**
51
+
41
52
```bash
42
53
export DEBUG=azure*,rhea*
43
54
```
55
+
44
56
- If you are **not interested in viewing the message transformation** (which consumes lot of console/disk space) then you can set the `DEBUG` environment variable as follows:
- You will find the sample provided below demonstrates a multi eph instance in the same process. Since node.js is single threaded, it has to load balance between managing(renew, steal, acquire, update) leases and receive messages across all the partitions. It is better to
69
-
create each instance in a separate process or a separate machine. This should provide better results.
85
+
86
+
- You will find the sample provided below demonstrates a multi eph instance in the same process. Since node.js is single threaded, it has to load balance between managing(renew, steal, acquire, update) leases and receive messages across all the partitions. It is better to
87
+
create each instance in a separate process or a separate machine. This should provide better results.
The following samples focus on EPH (Event Processor Host) which is responsible for receiving messages.
79
-
For sending messages to the EventHub, please use the `azure-event-hubs` package from npm. More
99
+
For sending messages to the EventHub, please use the `@azure/event-hubs` package from npm. More
80
100
information about the event hub client can be found over [here](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-hubs).
81
101
You can also use [this example](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-processor-host/samples/typescript/src/sendBatch.ts) that sends
82
102
multiple messages batched together. You should be able to run the `send` example from one terminal window and see those messages
@@ -135,6 +155,7 @@ main().catch((err) => {
135
155
```
136
156
137
157
### Multiple EPH instances in the same process.
158
+
138
159
This example creates 2 instances of EPH in the same process. It is also perfectly fine to create
139
160
multiple EPH instances in different processes on the same or different machine.
140
161
@@ -206,20 +227,35 @@ async function startEph(ephName /**string**/) {
// Checkpointing every 200th event that is received acrosss all the partitions.
214
243
if (count % 200 === 0) {
215
244
try {
216
-
console.log("***** [%s] EPH is currently receiving messages from partitions: %O", ephName,
217
-
eph.receivingFromPartitions);
245
+
console.log(
246
+
"***** [%s] EPH is currently receiving messages from partitions: %O",
247
+
ephName,
248
+
eph.receivingFromPartitions
249
+
);
218
250
await context.checkpoint();
219
251
console.log("$$$$ [%s] Successfully checkpointed message number %d", ephName, count);
220
252
} catch (err) {
221
-
console.log(">>>>>>> [%s] An error occurred while checkpointing msg number %d: %O",
222
-
ephName, count, err);
253
+
console.log(
254
+
">>>>>>> [%s] An error occurred while checkpointing msg number %d: %O",
255
+
ephName,
256
+
count,
257
+
err
258
+
);
223
259
}
224
260
}
225
261
};
@@ -267,7 +303,7 @@ async function main() {
267
303
);
268
304
let count = 0;
269
305
// Message event handler
270
-
const onMessage = async (context/*PartitionContext*/, data /*EventData*/) => {
306
+
const onMessage = async (context/*PartitionContext*/, data /*EventData*/) => {
271
307
console.log(">>>>> Rx message from '%s': '%s'", context.partitionId, data.body);
272
308
count++;
273
309
// let us checkpoint every 100th message that is received across all the partitions.
@@ -292,8 +328,8 @@ main().catch((err) => {
292
328
});
293
329
```
294
330
295
-
## AMQP Dependencies ##
296
-
It depends on [rhea](https://github.com/amqp/rhea) library for managing connections, 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.
331
+
## AMQP Dependencies
297
332
333
+
It depends on [rhea](https://github.com/amqp/rhea) library for managing connections, 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.
0 commit comments