Skip to content

Commit

Permalink
Add ACL to example config and enhance README
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Dec 2, 2016
1 parent c13c243 commit dd9b7d4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ Loopback Component for working with a Message Queue
{
"loopback-component-mq": {
"options": {
"dataSource": "rabbit"
"dataSource": "rabbit",
"acls": [{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$unauthenticated",
"permission": "ALLOW"
}]
},
"topology": {
"my-event-queue": {
Expand Down Expand Up @@ -56,6 +62,46 @@ Loopback Component for working with a Message Queue
}
```

## Configuration

The configuration of this component happens in `component-config.json`.

The 2 top-level keys are `options` and `topology` which are both objects.

### Options

The `options` object has 2 keys:

- `dataSource` (String, required). This is the name of the RabbitMQ datasource that is configured in `datasources.json`.
Please note that this datasource does not use any `loopback-connector-*` packages, but just a way to tell the component
how to connect to RabbitMQ.

- `acls` (Array, optional). Use this array to configure the ACL's. This ACL protects the Queue model that gets created.

### Topology

In the `topology` object you configure the queues served by this component. The object key is the name of the Queue.

Inside this queue definition you can define a `consumer`, a `producer`, or both. The `consumer` and `producer` objects
both accept 2 properties, `model` and `method`.

#### Consumer

When you defined a `consumer` on a queue, the component will call into the `Model.method()` defined when a new message
arrives on the queue. The method will be called with 2 parameters, `payload` and `ack`. Payload is the raw message from
the queue. The `ack` parameter is a message that is used to acknowledge to the queue that the message is being handled.
Make sure to acknowledge all messages, because RabbitMQ won't allow any other messages to be picked up until the message
is acknowledged, making the queue come to a halt.

#### Producer

When defining a `producer` on a queue, the component will create the method `Model.method()` defined. The method created
accepts 1 parameter, `payload`. The payload is the raw message that will be stored on the queue.

## TODO

- [] Add support for more types of Queues in the topology

## License

MIT
1 change: 0 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const Promise = require('bluebird')
const path = require('path')
const chai = require('chai')

Expand Down

0 comments on commit dd9b7d4

Please sign in to comment.