Skip to content

Commit

Permalink
Merge pull request #20 from plusmancn/feature/fix-producer-doc
Browse files Browse the repository at this point in the history
doc: update producer example
  • Loading branch information
gxcsoccer committed Sep 14, 2018
2 parents be96bbd + 5f358a4 commit eef0e01
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ producer

```js
'use strict';

const co = require('co');
const httpclient = require('urllib');
const Producer = require('ali-ons').Producer;
const Message = require('ali-ons').Message;
Expand All @@ -65,15 +65,18 @@ const producer = new Producer({
producerGroup: 'your-producer-group',
});

producer.ready(() => {
console.log('producer ready');
co(function*() {
const msg = new Message('your-topic', // topic
'TagA', // tag
'Hello ONS !!! ' // body
);

producer.send(msg, (err, sendResult) => console.log(err, sendResult));
});
// set Message#keys
msg.keys = ['key1'];

const sendResult = yield producer.send(msg);
console.log(sendResult);
}).catch(err => console.error(err))
```

## License
Expand Down

0 comments on commit eef0e01

Please sign in to comment.