Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Commit

Permalink
Merge 05083a4 into abe7f17
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Jun 18, 2016
2 parents abe7f17 + 05083a4 commit 651b25a
Show file tree
Hide file tree
Showing 33 changed files with 682 additions and 401 deletions.
1 change: 0 additions & 1 deletion .travis.yml
@@ -1,7 +1,6 @@
language: node_js
sudo: false
node_js:
- 0.10
- 0.12
- 4
- 6
Expand Down
31 changes: 2 additions & 29 deletions README.md
Expand Up @@ -28,8 +28,8 @@ Mosca   [![Build Status](https://travis-ci.org/mcollina/mosca.svg
### Standalone

```bash
npm install mosca bunyan -g
mosca -v | bunyan
npm install mosca pino -g
mosca -v | pino
```

### Embedded
Expand Down Expand Up @@ -124,37 +124,10 @@ Chat with us on [Mosca's room](https://gitter.im/mcollina/mosca) on Gitter.
* [MQTT protocol](http://mqtt.org)
* [MQTT.js](http://github.com/adamvr/MQTT.js)


## Authors

[Matteo Collina](http://twitter.com/matteocollina)

## Contributors

<table><tbody>
<tr><th align="left">David Halls</th><td><a
href="https://github.com/davedoesdev">GitHub/davedoesdev</a></td>
</tr>
<tr><th align="left">Andrea Reginato</th><td><a
href="https://github.com/andreareginato">GitHub/andreareginato</a></td>
</tr>
<tr><th align="left">Chris Wiggins</th><td><a
href="https://github.com/chriswiggins">GitHub/chriswiggins</a></td>
</tr>
<tr><th align="left">Samir Naik</th><td><a
href="https://github.com/samirnaik">GitHub/samirnaik</a></td>
</tr>
<tr><th align="left">Leo Steiner</th><td><a
href="https://github.com/ldstein">GitHub/ldstein</a></td>
</tr>
<tr><th align="left">John Kokkinidis</th><td><a
href="https://github.com/SudoPlz">GitHub/SudoPlz</a></td>
</tr>
<tr><th align="left">Morgan Cheng</th><td><a
href="https://github.com/mocheng">GitHub/mocheng</a></td>
</tr>
</tbody></table>

## Logo
[Sam Beck](http://two-thirty.tumblr.com)

Expand Down
25 changes: 25 additions & 0 deletions examples/kafka/Dockerfile
@@ -0,0 +1,25 @@
FROM mhart/alpine-node:4
MAINTAINER Robert Fuller <fullergalway@gmail.com>

RUN apk update && \
apk add make gcc g++ python git

RUN mkdir -p /usr/src/app
RUN mkdir -p /app/db

WORKDIR /usr/src/app/

COPY ./ /usr/src/app/

RUN npm install --unsafe-perm --production
RUN npm install -g browserify uglify-js
RUN browserify -r mqtt -s mqtt | uglifyjs --screw-ie8 > public/mqtt.js

COPY examples/kafka/server.js lib/mosca_kafka_server.js
COPY examples/kafka/auth.json auth.json
COPY examples/kafka/index.html public/

EXPOSE 80
EXPOSE 1883

ENTRYPOINT ["node","lib/mosca_kafka_server.js"]
56 changes: 56 additions & 0 deletions examples/kafka/README.md
@@ -0,0 +1,56 @@
Kafka MQTT Bridge Example
=========================

Here is a Mosca example to expose an MQTT interface to [kafka](//kafka.apache.org). Try it right now in docker!

Quickstart
----------

1. To try out the example with no changes, start a kafka server:

docker run -d --env ADVERTISED_HOST=kafka01 --hostname=kafka01 --env ADVERTISED_PORT=9092 --name=kafka01 spotify/kafka

2. Once the kafka is running, use the console producer to create some expected topics.

for topic in spiddal-ctd \
spiddal-fluorometer \
airmar-rinville-1 \
ais-rinville-1-geojson \
spiddal-hydrophone
do docker exec -i -t kafka01 /bin/bash -c \
"date | /opt/kafka_*/bin/kafka-console-producer.sh \
--broker-list kafka01:9092 --topic $topic"
done

3. Now start the kakfka mqtt bridge, linked to the kafka instance.

docker run -d -p 2298:80 --link kafka01:kafka01 --link kafka01:kafka02 --link kafka01:kafka03 fullergalway/kafkamqtt

4. Open up your browser and go to http://server:2298 for example [http://localhost:2298](http://localhost:2298)

5. Finally, publish some data to your kafka topics by repeating step 2 above, and watch the data appear in your browser.

Building
--------

Before building, you might like to modify [auth.json](auth.json) and [index.html](index.html) to reference your own topics.

docker build -f examples/kafka/Dockerfile -t kafkamqtt .


Running
--------

To run the mosca mqtt server connected to your own kafka, provide the ip addresses when launching your docker container. (You'll need to add all three hosts (kafka01,kafka02,kafka03); repeat the ip address if you have fewer than three nodes in your cluster).

docker run -d --name=kafkamqtt -p 2298:80 --add-host="kafka01:172.17.1.86" --add-host="kafka02:172.17.1.87" --add-host="kafka03:172.17.1.88" kafkamqtt


Credits
-------

* [Matteo Collina](//twitter.com/matteocollina)
* [Robert Fuller](//github.com/fullergalway)
* [Adam Leadbetter](//twitter.com/adamleadbetter)
* [Damian Smyth](//ie.linkedin.com/in/damian-smyth-4b85563)
* [Eoin O'Grady](//ie.linkedin.com/in/eoin-o-grady-6177b)
21 changes: 21 additions & 0 deletions examples/kafka/auth.json
@@ -0,0 +1,21 @@
{
"_README": "To generate a password for this authfile do: echo -n 'usernamePassword' | md5sum",
"*": {
"comment": "These topics available for all users, whether authorized or not",
"password": "",
"subscribe": [
"airmar-rinville-1",
"spiddal-ctd",
"spiddal-fluorometer",
"spiddal-hydrophone",
"spiddal-adcp" ],
"publish": []
},
"fred": {
"password": "cc8355a2cc9fc3e0ed575db2f49268d1",
"subscribe": [
"ais-rinville-1-geojson"
],
"publish": []
}
}
98 changes: 98 additions & 0 deletions examples/kafka/index.html
@@ -0,0 +1,98 @@
<!doctype html>
<html>
<head>
<style>
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 5px 5px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 12px;
}
.error {
color: #D8000C;
background-color: #FFBABA;
}
.hidden {
visibility: hidden;
display: none
}
</style>
<script src="/mqtt.js"></script>
<title>Marine Institute MQTT live demo</title>
</head>
<body>
<div id="errors" class="error"></div>
<h1>CTD</h1>
<pre id="spiddal-ctd"></pre>
<h1>Fluorometer</h1>
<pre id="spiddal-fluorometer"></pre>
<h1>Weather</h1>
<pre id="airmar-rinville-1"></pre>
<h1>AIS</h1>
<pre id="ais-rinville-1-geojson"></pre>
<h1>Hydrophone</h1>
<pre id="spiddal-hydrophone"></pre>
<div id="login" class="hidden">
<input class="username" placeholder="username">
<input class="password" type="password" placeholder="password">
<input class="login-button button" type="button" value="Login">
</div>
<script>
var showlogin = function(){
var el = document.getElementById("ais-rinville-1-geojson");
if(el.innerHTML !== ""){
// already done.
return;
}
el.innerHTML = document.getElementById("login").innerHTML;
document.querySelector(".login-button").addEventListener('click',function(){
var username = document.querySelector('.username').value;
var password = document.querySelector('.password').value;
document.getElementById("ais-rinville-1-geojson").innerHTML = "";
document.getElementById("errors").textContent = "";
doconnect(["spiddal-ctd",
"spiddal-fluorometer",
"spiddal-hydrophone",
"airmar-rinville-1",
"ais-rinville-1-geojson"],username,password);
});
}
var client;
var doconnect = function(topics,username,password){
if(client){
client.end(true);
client = null;
}
if(username){
client = mqtt.connect({username: username, password: password});
}else{
client = mqtt.connect();
}
client.on("message", function(topic, payload) {
document.getElementById("errors").textContent = "";
document.getElementById(topic).textContent = payload;
});
client.on('connect', function(err) {
document.getElementById("errors").textContent = "";
});
client.on('error', function(err) {
document.getElementById("errors").textContent = err.toString();
showlogin();
});
for(var i=0;i<topics.length;i++){
client.subscribe(topics[i]);
}
}
showlogin();

doconnect(["spiddal-ctd",
"spiddal-fluorometer",
"spiddal-hydrophone",
"airmar-rinville-1"]);
</script>
</body>
</html>

0 comments on commit 651b25a

Please sign in to comment.