socket.io-java-emitter
socket.io-java-emitter copied to clipboard
A Java implementation of socket.io-emitter
socket.io-java-emitter
A Java implementation of socket.io-emitter
This project uses msgpack-java and jedis.
Usage
Using an existing redis instance
JedisPool jedis = new JedisPool(new JedisPoolConfig(), "127.0.0.1", 6379);
Emitter emitter = Emitter.getInstance(jedis, new HashMap<String,String>());
Emitter emitter = Emitter.getInstance(null, opts);
emitter.of("/namespace").emit("event", "Hello World!");
Emitting without manually creating a redis instance
HashMap<String,String> opts = new HashMap<String,String>();
opts.put("host", "127.0.0.1");
opts.put("port", "6379");
Emitter emitter = Emitter.getInstance(null, opts);
emitter.of("/namespace").emit("event", "Hello World!");
Broadcasting and other flags
Possible flags
- json
- volatile
- broadcast
Emitter emitter = Emitter.getInstance(null, ImmutableMap.of("host", "127.0.0.1", "port", "6379"));
// broadcast can be replaced by any of the other flags
emitter.of("/namespace").broadcast().emit("event", "Hello World!");
Emitting objects
Emitter emitter = Emitter.getInstance(null, ImmutableMap.of("host", "127.0.0.1", "port", "6379"));
String jsonData = "{\"test\":[\"test\",\"test1\"],\"name\":\"xxxxx\",\"id\":1234,\"float\":1234.00,\"bool\":true,\"object\":{\"name\":\"xxxxx\",\"id\":1234}}";
JSONObject jsonRoot = new JSONObject(jsonData);
emitter.of("/namespace").emit("event", jsonRoot);
Dependencies
This module requires a Redis to be available on the network.
License
Copyright © 2014 sunsus GmbH
Distributed under the MIT License.