Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rascal

Package Overview
Dependencies
Maintainers
1
Versions
183
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rascal - npm Package Compare versions

Comparing version 0.1.1 to 0.1.3

5

examples/readme.js
var rascal = require('..')
var _ = require('lodash').runInContext().mixin({ 'defaultsDeep': require('merge-defaults') })
var definitions = require('./definitions.json')
var config = _.defaultsDeep(definitions, rascal.defaults)
var config = rascal.withDefaultConfig(definitions)
rascal.Broker.create(config, function(err, broker) {
rascal.createBroker(config, function(err, broker) {
if (err) console.error(err.message) & process.exit(1)

@@ -9,0 +8,0 @@ broker.subscribe('s1', function(err, message, content, next) {

4

examples/server.js
var debug = require('debug')('amqp-nice:server')
var _ = require('lodash').runInContext()
var _ = require('lodash').runInContext().mixin({ 'defaultsDeep': require('merge-defaults') })
var Broker = require('../lib/amqp/Broker')

@@ -7,4 +7,2 @@ var defaultConfig = require('../lib/config/defaults')

_.mixin({ 'defaultsDeep': require('merge-defaults') });
var config = _.defaultsDeep({

@@ -11,0 +9,0 @@ vhosts: {

'use strict'
var defaults = require('./lib/config/defaults')
var _ = require('lodash').runInContext().mixin({ 'defaultsDeep': require('merge-defaults') })
var defaultConfig = require('./lib/config/defaults')
var testConfig = require('./lib/config/tests')
var Broker = require('./lib/amqp/Broker')

@@ -9,4 +11,12 @@

Broker: Broker,
defaults: defaults
createBroker: Broker.create,
defaultConfig: defaultConfig,
testConfig: testConfig,
withDefaultConfig: function(config) {
return _.defaultsDeep(config, defaultConfig)
},
withTestConfig: function(config) {
return _.defaultsDeep(config, testConfig)
}
}
})()

@@ -32,3 +32,3 @@ var debug = require('debug')('amqp-nice:Vhost')

ctx.connection.removeAllListeners('error')
// if (config.connection.retry) ctx.connection.once('error', handleConnectionError.bind(null, config))
if (config.connection.retry) ctx.connection.once('error', handleConnectionError.bind(null, config))
connection = ctx.connection

@@ -35,0 +35,0 @@ channelAllocator.resume()

{
"name": "rascal",
"version": "0.1.1",
"version": "0.1.3",
"description": "A friendly wrapper around amqplib with safe defaults",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -9,8 +9,7 @@ # Rascal

var rascal = require('rascal')
var _ = require('lodash').runInContext().mixin({ 'defaultsDeep': require('merge-defaults') })
var definitions = require('./definitions.json')
var config = _.defaultsDeep(definitions, rascal.defaults)
var config = rascal.withDefaultConfig(definitions)
rascal.Broker.create(config, function(err, broker) {
rascal.createBroker(config, function(err, broker) {
if (err) console.error(err.message) & process.exit(1)

@@ -22,4 +21,4 @@ broker.subscribe('s1', function(err, message, content, next) {

setInterval(function() {
broker.publish('p1', 'This is a test message')
}, 100).unref()
broker.publish('p1', 'This is a test message')
}, 100).unref()
})

@@ -61,2 +60,151 @@ ```

```
## Configuration
Default Test conflab link to rabbit docs
### vhosts
#### namespace
Running automated tests against shared queues and exchanges is problematic. Messages left over from a previous test run can cause assertions to fail. Rascal has several strategies which help you cope with this problem, one of which is to namespace your queues and exchange. By specifying ```"namespace" :true``` Rascal will prefix the queues and exchanges it creates with a uuid. Alternatively you can specify your own namespace, ```"namespace": "foo"```. Namespaces are also if you want to use a single vhost locally but multiple vhosts in other environments.
#### connection
The simplest way to specify a connection is with a url
```json
"vhosts": {
"v1": {
"connection": {
"url": "amqp://guest:guest@example.com:5672/v1?heartbeat=10"
}
}
}
If this doesn't work for you, then you can specify the individual connection details
```json
"vhosts": {
"v1": {
"connection": {
"slashes": true,
"protocol": "amqp",
"hostname": "localhost",
"user": "guest",
"password": "guest",
"port": 5672,
"vhost": "v1",
"options": {
heartbeat: 5
}
}
}
}
```
Any attributes you add to the "options" sub document will be converted to query parameters. Providing you merge your configuration with the default configuration ```rascal.withDefaultConfig(config)``` you need only specify the attributes you need to override
```json
"vhosts": {
"v1": {
"connection": {
"hostname": "example.com",
"user": "bob",
"password": "secret",
"vhost": "v1"
}
}
}
```
Rascal also supports automatic connection retries. It's enabled in the default config, or you want enable it specifically as follows.
```
"vhosts": {
"v1": {
"connection": {
"retry": {
"delay": 1000
}
}
}
}
```
#### exchanges
##### assert
Setting assert to true will cause Rascal to create the exchange on initialisation. If the exchange already exists and has the same configuration (type, durability, etc) everything will be fine, however if the existing exchange has a different configuration an error will be returned. Assert is enabled in the default configuration.
##### check
If you don't want to create exchanges on initialisation, but still want to validate that they exist set assert to false and check to true
```json
"vhosts": {
"v1": {
"exchanges": {
"e1": {
"assert": false,
"check": true
}
}
}
}
```
##### type
Declares the exchange type. Must be one of direct, topic, headers or fanout. The default configuration sets the exchange type to "topic" unless overriden.
##### options
Define any further configuration in an options block
```json
"vhosts": {
"v1": {
"exchanges": {
"e1": {
"type": "fanout",
"options": {
"durable": false
}
}
}
}
}
```
Refer to the excellent [amqplib](http://www.squaremobius.net/amqp.node/doc/channel_api.html) documentation for further exchange options.
#### queues
##### assert
Setting assert to true will cause Rascal to create the queue on initialisation. If the queue already exists and has the same configuration (durability, etc) everything will be fine, however if the existing queue has a different configuration an error will be returned. Assert is enabled in the default configuration.
##### check
If you don't want to create queues on initialisation, but still want to validate that they exist set assert to false and check to true
```json
"vhosts": {
"v1": {
"queues": {
"q1": {
"assert": false,
"check": true
}
}
}
}
```
#### purge
Enable to purge the queue during initialisation. Useful when running automated tests
"vhosts": {
"v1": {
"queues": {
"q1": {
"purge": true
}
}
}
}
```
##### options
Define any further configuration in an options block
```json
"queues": {
"q1": {
"options": {
"durable": false,
"exclusive": true
}
}
}
```
Refer to the excellent [amqplib](http://www.squaremobius.net/amqp.node/doc/channel_api.html) documentation for further queue options.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc