summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mrexodia/wray/README.markdown
blob: 64c1e83369edbbc82a6f8d8261da33c78919b21d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Wray, faye client for Go

Wray is a client for the [Faye](http://faye.jcoglan.com) publish-subscribe messaging service by [James Coglan](https://twitter.com/jcoglan).

## Current status

In progress.

## Getting Started

Wray is only a client for Faye. You will need to setup a server using Ruby or Node.js first. Instructions that can be found on the [Faye project pages](http://faye.jcoglan.com/).

###Subscribing to channels

```
package main

import "github.com/pythonandchips/wray"
import "fmt"

func main() {
  //register the types of transport you want available. Only long-polling is currently supported
  wray.RegisterTransports([]gofaye.Transport{ &gofaye.HttpTransport{} })

  //create a new client
  client := wray.NewFayeClient("http://localhost:5000/faye")

  //subscribe to the channels you want to listen to
  client.Subscribe("/foo", false, func(message wray.Message) {
    fmt.Println("-------------------------------------------")
    fmt.Println(message.Data)
  })

  //wildcards can be used to subscribe to multipule channels
  client.Subscribe("/foo/*", false, func(message wray.Message) {
    fmt.Println("-------------------------------------------")
    fmt.Println(message.Data)
  })

  //start listening on all subscribed channels and hold the process open
  client.Listen()
}
```

###Publishing to channels
```
package main

import "github.com/pythonandchips/wray"
import "fmt"

func main() {
  //register the types of transport you want available. Only long-polling is currently supported
  wray.RegisterTransports([]wray.Transport{ &gofaye.HttpTransport{} })

  //create a new client
  client := wray.NewFayeClient("http://localhost:5000/faye")

  params := map[string]interface{}{"hello": "from golang"}

  //send message to server
  client.Publish("/foo", params)
}
```

Simple examples are availabe in the examples folder.

##Future Work
There is still a lot to do to bring Wray in line with Faye functionality. This is a less than exhaustive list of work to be completed:-

- web socket support
- eventsource support
- logging
- middleware additions
- correctly handle disconnect and server down
- promises for subscription and publishing
- automated integrations test to ensure Wray continues to work with Faye

## Bugs/Features/Prase

It you find any bugs or have some feature requests please add an issue on the repository. Or if you just want to get in touch and tell me how awesome wray is you can get me on twitter @colin_gemmell or drop me an email at pythonandchips{at}gmail.com.

## Contributing to Wray

* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
* Fork the project
* Start a feature/bugfix branch
* Commit and push until you are happy with your contribution
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

## Copyright

Copyright (c) 2014 Colin Gemmell

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.