Merge pull request #189 from andsel/mackristof-feat/cluster
Mackristof feat/cluster
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package io.moquette.interception;
|
||||
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.core.ITopic;
|
||||
import io.moquette.interception.messages.InterceptPublishMessage;
|
||||
import io.moquette.server.Server;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Created by mackristof on 28/05/2016.
|
||||
*/
|
||||
public class HazelcastInterceptHandler extends AbstractInterceptHandler {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HazelcastInterceptHandler.class);
|
||||
private final HazelcastInstance hz;
|
||||
|
||||
public HazelcastInterceptHandler (Server server){
|
||||
this.hz = server.getHazelcastInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPublish(InterceptPublishMessage msg) {
|
||||
LOG.info("{} publish on {} message: {}", msg.getClientID(), msg.getTopicName(), new String(msg.getPayload().array()));
|
||||
ITopic<HazelcastMsg> topic = hz.getTopic("moquette");
|
||||
HazelcastMsg hazelcastMsg = new HazelcastMsg(msg.getClientID(), msg.getTopicName(), msg.getQos().byteValue(),
|
||||
msg.getPayload().array(), msg.getUsername());
|
||||
topic.publish(hazelcastMsg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package io.moquette.interception;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by mackristof on 28/05/2016.
|
||||
*/
|
||||
public class HazelcastMsg implements Serializable {
|
||||
|
||||
private final String clientId;
|
||||
private final String userName;
|
||||
private final byte qos;
|
||||
private final byte[] payload;
|
||||
private final String topic;
|
||||
|
||||
public HazelcastMsg(String clientId, String topic, byte qos, byte[] payload, String userName) {
|
||||
this.clientId = clientId;
|
||||
this.qos = qos;
|
||||
this.payload = payload;
|
||||
this.userName = userName;
|
||||
this.topic = topic;
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public byte getQos() {
|
||||
return qos;
|
||||
}
|
||||
|
||||
public byte[] getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public String getTopic() {
|
||||
return topic;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user