|
1 |
| -import { CloudEvent, HTTPREceiver } from '../../'; |
| 1 | +import { CloudEvent, HTTPReceiver } from '../../..'; |
| 2 | +import { CloudEventV1 } from '../../../lib/v1'; |
2 | 3 |
|
3 | 4 | export function doSomeStuff() {
|
4 |
| - const receiver = new HTTPREceiver(); |
| 5 | + const receiver = new HTTPReceiver(); |
5 | 6 |
|
6 |
| - const myevent: CloudEvent = new CloudEvent() |
7 |
| - .source('/source') |
8 |
| - .type('type') |
9 |
| - .dataContentType('text/plain') |
10 |
| - .dataschema('http://d.schema.com/my.json') |
11 |
| - .subject('cha.json') |
12 |
| - .data('my-data') |
13 |
| - .addExtension("my-ext", "0x600"); |
| 7 | + const myevent: CloudEventV1 = new CloudEvent({ |
| 8 | + source: '/source', |
| 9 | + type: 'type', |
| 10 | + dataContentType: 'text/plain', |
| 11 | + dataSchema: 'https://d.schema.com/my.json', |
| 12 | + subject: 'cha.json', |
| 13 | + data: 'my-data' |
| 14 | + }); |
| 15 | + myevent.addExtension('extension-1', 'some extension data'); |
14 | 16 |
|
15 |
| - console.log(myevent.toString()); |
16 |
| - console.log(myevent.getExtensions()); |
| 17 | + console.log("My structured event:", myevent.toString()); |
| 18 | + console.log("My structured event extensions:", myevent.getExtensions()); |
17 | 19 |
|
18 | 20 | // ------ receiver structured
|
19 |
| - const payload = myevent.toString(); |
20 | 21 | const headers = {
|
21 |
| - "Content-Type":"application/cloudevents+json" |
| 22 | + "content-type": "application/cloudevents+json" |
22 | 23 | };
|
23 | 24 |
|
24 |
| - console.log(receiver.accept(headers, payload).toString()); |
| 25 | + // Typically used with an incoming HTTP request where myevent.format() is the actual |
| 26 | + // body of the HTTP |
| 27 | + console.log('Received structured event:', receiver.accept(headers, myevent.format()).toString()); |
25 | 28 |
|
26 | 29 | // ------ receiver binary
|
27 |
| - const extension1 = "mycuston-ext1"; |
28 | 30 | const data = {
|
29 |
| - "data" : "dataString" |
| 31 | + "data": "dataString" |
30 | 32 | };
|
31 | 33 | const attributes = {
|
32 |
| - "ce-type" : "type", |
33 |
| - "ce-specversion" : "1.0", |
34 |
| - "ce-source" : "source", |
35 |
| - "ce-id" : "id", |
36 |
| - "ce-time" : "2019-06-16T11:42:00Z", |
37 |
| - "ce-dataschema" : "http://schema.registry/v1", |
38 |
| - "Content-Type" : "application/json", |
39 |
| - "ce-extension1" : extension1 |
| 34 | + "ce-type": "type", |
| 35 | + "ce-specversion": "1.0", |
| 36 | + "ce-source": "source", |
| 37 | + "ce-id": "id", |
| 38 | + "ce-time": "2019-06-16T11:42:00Z", |
| 39 | + "ce-dataschema": "http://schema.registry/v1", |
| 40 | + "Content-Type": "application/json", |
| 41 | + "ce-extension1": "extension1" |
40 | 42 | };
|
41 | 43 |
|
42 |
| - console.log(receiver.accept(attributes, data).toString()); |
| 44 | + console.log("My binary event:", receiver.accept(attributes, data).toString()); |
| 45 | + console.log("My binary event extensions:", receiver.accept(attributes, data).toString()); |
43 | 46 |
|
44 | 47 | return true;
|
45 | 48 | }
|
|
0 commit comments