Simplyfied creation of HazelcastMsg from InterceptPublishMessage
This commit is contained in:
@@ -23,8 +23,7 @@ public class HazelcastInterceptHandler extends AbstractInterceptHandler {
|
||||
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());
|
||||
HazelcastMsg hazelcastMsg = new HazelcastMsg(msg);
|
||||
topic.publish(hazelcastMsg);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.moquette.interception;
|
||||
|
||||
import io.moquette.interception.messages.InterceptPublishMessage;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -8,17 +10,15 @@ import java.io.Serializable;
|
||||
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 HazelcastMsg(InterceptPublishMessage msg) {
|
||||
this.clientId = msg.getClientID();
|
||||
this.topic = msg.getTopicName();
|
||||
this.qos = msg.getQos().byteValue();
|
||||
this.payload = msg.getPayload().array();
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
@@ -33,10 +33,6 @@ public class HazelcastMsg implements Serializable {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public String getTopic() {
|
||||
return topic;
|
||||
}
|
||||
|
||||
@@ -26,14 +26,15 @@ public class HazelcastListener implements MessageListener<HazelcastMsg> {
|
||||
public void onMessage(Message<HazelcastMsg> msg) {
|
||||
try {
|
||||
if (!msg.getPublishingMember().equals(server.getHazelcastInstance().getCluster().getLocalMember())) {
|
||||
LOG.info("{} received from hazelcast for topic {} message: {}", msg.getMessageObject().getClientId(),
|
||||
msg.getMessageObject().getTopic(), msg.getMessageObject().getPayload());
|
||||
HazelcastMsg hzMsg = msg.getMessageObject();
|
||||
LOG.info("{} received from hazelcast for topic {} message: {}", hzMsg.getClientId(),
|
||||
hzMsg.getTopic(), hzMsg.getPayload());
|
||||
PublishMessage publishMessage = new PublishMessage();
|
||||
publishMessage.setTopicName(msg.getMessageObject().getTopic());
|
||||
publishMessage.setQos(AbstractMessage.QOSType.valueOf(msg.getMessageObject().getQos()));
|
||||
publishMessage.setPayload(ByteBuffer.wrap(msg.getMessageObject().getPayload()));
|
||||
publishMessage.setTopicName(hzMsg.getTopic());
|
||||
publishMessage.setQos(AbstractMessage.QOSType.valueOf(hzMsg.getQos()));
|
||||
publishMessage.setPayload(ByteBuffer.wrap(hzMsg.getPayload()));
|
||||
publishMessage.setLocal(false);
|
||||
publishMessage.setClientId(msg.getMessageObject().getClientId());
|
||||
publishMessage.setClientId(hzMsg.getClientId());
|
||||
server.internalPublish(publishMessage);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
||||
Reference in New Issue
Block a user