This repository has been archived by the owner on Feb 11, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
682 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
language: node_js | ||
sudo: false | ||
node_js: | ||
- 0.10 | ||
- 0.12 | ||
- 4 | ||
- 6 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Oops, something went wrong.