README.md in message_bus-2.0.0.beta.2 vs README.md in message_bus-2.0.0.beta.3
- old
+ new
@@ -1,8 +1,8 @@
# MessageBus
-A reliable, robust messaging bus for Ruby processes and web clients built on Redis.
+A reliable, robust messaging bus for Ruby processes and web clients.
MessageBus implements a Server to Server channel based protocol and Server to Web Client protocol (using polling, long-polling or long-polling + streaming)
Long-polling is implemented using Rack Hijack and Thin::Async, all common Ruby web server can run MessageBus (Thin, Puma, Unicorn) and handle a large amount of concurrent connections that wait on messages.
@@ -47,25 +47,25 @@
MessageBus.backlog "/channel", id
# returns all messages after the id
# messages can be targetted at particular users or groups
-MessageBus.publish "/channel", user_ids: [1,2,3], group_ids: [4,5,6]
+MessageBus.publish "/channel", "hello", user_ids: [1,2,3], group_ids: [4,5,6]
# messages can be targetted at particular clients (using MessageBus.clientId)
-MessageBus.publish "/channel", client_ids: ["XXX","YYY"]
+MessageBus.publish "/channel", "hello", client_ids: ["XXX","YYY"]
# message bus determines the user ids and groups based on env
-MessageBus.user_id_lookup do |env|
+MessageBus.configure(user_id_lookup: proc do |env|
# return the user id here
-end
+end)
-MessageBus.group_ids_lookup do |env|
+MessageBus.configure(group_ids_lookup: proc do |env|
# return the group ids the user belongs to
# can be nil or []
-end
+end)
```
### Transport
MessageBus ships with 3 transport mechanisms.
@@ -98,11 +98,11 @@
```
Or
```
-MessageBus.chunked_encoding_enabled = false // in Ruby
+MessageBus.configure(chunked_encoding_enabled: false) // in Ruby
```
Long Polling requires no special setup, as soon as new data arrives on the channel the server delivers the data and closes the connection.
Polling also requires no special setup, MessageBus will fallback to polling after a tab becomes inactive and remains inactive for a period.
@@ -111,13 +111,13 @@
MessageBus can be used in an environment that hosts multiple sites by multiplexing channels. To use this mode
```ruby
# define a site_id lookup method
-MessageBus.site_id_lookup do
+MessageBus.configure(site_id_lookup: proc do
some_method_that_returns_site_id_string
-end
+end)
# you may post messages just to this site
MessageBus.publish "/channel", "some message"
# you may publish messages to ALL sites using the /global/ prefix
@@ -135,21 +135,30 @@
```html
<script src="message-bus.js" type="text/javascript"></script>
```
Note, the message-bus.js file is located in the assets folder.
+**Rails**
```javascript
+//= require message-bus
+```
+
+```javascript
MessageBus.start(); // call once at startup
// how often do you want the callback to fire in ms
MessageBus.callbackInterval = 500;
MessageBus.subscribe("/channel", function(data){
// data shipped from server
});
```
+There is also a Ruby implementation of the client library, at
+[message_bus-client](https://github.com/lowjoel/message_bus-client) with the API very similar to
+that of the JavaScript client.
+
**Client settings**:
All client settings are settable via `MessageBus.OPTION`
@@ -177,26 +186,43 @@
`MessageBus.subscribe(channel,func,lastId)` : Subscribe to a channel, optionally you may specify the id of the last message you received in the channel.
`MessageBus.unsubscribe(channel,func)` : Unsubscribe callback from a particular channel
+## Running tests
+To run tests you need both Postgres and Redis installed. By default we will connect to the database `message_bus_test` with the current username. If you wish to override this:
+```
+PGUSER=some_user PGDATABASE=some_db bundle exec rake
+```
+
+
## Configuration
### Redis
You can configure redis setting in `config/initializers/message_bus.rb`, like
```ruby
-MessageBus.redis_config = { url: "redis://:p4ssw0rd@10.0.1.1:6380/15" }
+MessageBus.configure(backend: :redis, url: "redis://:p4ssw0rd@10.0.1.1:6380/15")
```
The redis client message_bus uses is [redis-rb](https://github.com/redis/redis-rb), so you can visit it's repo to see what options you can configure.
+### PostgreSQL
+
+message_bus also supports PostgreSQL as the backend:
+
+```ruby
+MessageBus.configure(backend: :postgres, backend_options: {user: 'message_bus', dbname: 'message_bus'})
+```
+
+The PostgreSQL client message_bus uses is [ruby-pg](https://bitbucket.org/ged/ruby-pg), so you can visit it's repo to see what options you can configure.
+
### Forking/threading app servers
-If you're using a forking or threading app server and you're not getting immediate updates from published messages, you might need to reconnect Redis in your app server config:
+If you're using a forking or threading app server and you're not getting immediate updates from published messages, you might need to reconnect Redis/PostgreSQL in your app server config:
#### Passenger
```ruby
# Rails: config/application.rb or config.ru
if defined?(PhusionPassenger)
@@ -227,16 +253,17 @@
after_fork do |server, worker|
MessageBus.after_fork
end
```
+###
+
## Want to help?
If you are looking to contribute to this project here are some ideas
-- Build an in-memory storage backend to ease testing and for very simple deployments
-- Build a PostgreSQL backend using NOTIFY and LISTEN
-- Improve general documentation
-- Port the test suite to MiniTest
+- Build backends for other providers (zeromq, rabbitmq, disque)
+- Improve and properly document admin dashboard (add opt-in stats, better diagnostics into queues)
+- Improve general documentation (Add examples, refine existing examples)
- Make MessageBus a nice website