热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

io.netty.handler.codec.mqtt.MqttPublishMessage.variableHeader()方法的使用及代码示例

本文整理了Java中io.netty.handler.codec.mqtt.MqttPublishMessage.variableHeader()方法的一些代码示例,展

本文整理了Java中io.netty.handler.codec.mqtt.MqttPublishMessage.variableHeader()方法的一些代码示例,展示了MqttPublishMessage.variableHeader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MqttPublishMessage.variableHeader()方法的具体详情如下:
包路径:io.netty.handler.codec.mqtt.MqttPublishMessage
类名称:MqttPublishMessage
方法名:variableHeader

MqttPublishMessage.variableHeader介绍

暂无

代码示例

代码示例来源:origin: andsel/moquette

public String getTopicName() {
return msg.variableHeader().topicName();
}

代码示例来源:origin: wildfly/wildfly

@Override
public MqttPublishMessage replace(ByteBuf content) {
return new MqttPublishMessage(fixedHeader(), variableHeader(), content);
}

代码示例来源:origin: andsel/moquette

/**
* Use the broker to publish a message. It's intended for embedding applications. It can be used
* only after the integration is correctly started with startServer.
*
* @param msg the message to forward.
* @param clientId the id of the sending integration.
* @throws IllegalStateException if the integration is not yet started
*/
public void internalPublish(MqttPublishMessage msg, final String clientId) {
final int messageID = msg.variableHeader().packetId();
if (!initialized) {
LOG.error("Moquette is not started, internal message cannot be published. CId: {}, messageId: {}", clientId,
messageID);
throw new IllegalStateException("Can't publish on a integration is not yet started");
}
LOG.trace("Internal publishing message CId: {}, messageId: {}", clientId, messageID);
dispatcher.internalPublish(msg);
}

代码示例来源:origin: andsel/moquette

@Override
public void notifyTopicPublished(final MqttPublishMessage msg, final String clientID, final String username) {
msg.retain();
executor.execute(() -> {
try {
int messageId = msg.variableHeader().messageId();
String topic = msg.variableHeader().topicName();
for (InterceptHandler handler : handlers.get(InterceptPublishMessage.class)) {
LOG.debug("Notifying MQTT PUBLISH message to interceptor. CId={}, messageId={}, topic={}, "
+ "interceptorId={}", clientID, messageId, topic, handler.getID());
handler.onPublish(new InterceptPublishMessage(msg, clientID, username));
}
} finally {
ReferenceCountUtil.release(msg);
}
});
}

代码示例来源:origin: andsel/moquette

void sendPublish(MqttPublishMessage publishMsg) {
final int packetId = publishMsg.variableHeader().packetId();
final String topicName = publishMsg.variableHeader().topicName();
final String clientId = getClientId();
MqttQoS qos = publishMsg.fixedHeader().qosLevel();
if (LOG.isTraceEnabled()) {
LOG.trace("Sending PUBLISH({}) message. MessageId={}, CId={}, topic={}, payload={}", qos, packetId,
clientId, topicName, DebugUtils.payload2Str(publishMsg.payload()));
} else {
LOG.debug("Sending PUBLISH({}) message. MessageId={}, CId={}, topic={}", qos, packetId, clientId,
topicName);
}
sendIfWritableElseDrop(publishMsg);
}

代码示例来源:origin: wildfly/wildfly

private static ByteBuf encodePublishMessage(
ByteBufAllocator byteBufAllocator,
MqttPublishMessage message) {
MqttFixedHeader mqttFixedHeader = message.fixedHeader();
MqttPublishVariableHeader variableHeader = message.variableHeader();
ByteBuf payload = message.payload().duplicate();
String topicName = variableHeader.topicName();
byte[] topicNameBytes = encodeStringUtf8(topicName);
int variableHeaderBufferSize = 2 + topicNameBytes.length +
(mqttFixedHeader.qosLevel().value() > 0 ? 2 : 0);
int payloadBufferSize = payload.readableBytes();
int variablePartSize = variableHeaderBufferSize + payloadBufferSize;
int fixedHeaderBufferSize = 1 + getVariableLengthInt(variablePartSize);
ByteBuf buf = byteBufAllocator.buffer(fixedHeaderBufferSize + variablePartSize);
buf.writeByte(getFixedHeaderByte1(mqttFixedHeader));
writeVariableLengthInt(buf, variablePartSize);
buf.writeShort(topicNameBytes.length);
buf.writeBytes(topicNameBytes);
if (mqttFixedHeader.qosLevel().value() > 0) {
buf.writeShort(variableHeader.messageId());
}
buf.writeBytes(payload);
return buf;
}

代码示例来源:origin: blynkkk/blynk-server

@Override
public void messageReceived(ChannelHandlerContext ctx, MqttMessage msg) {
this.stats.incrementMqttStat();
MqttMessageType messageType = msg.fixedHeader().messageType();
switch (messageType) {
case PUBLISH :
MqttPublishMessage publishMessage = (MqttPublishMessage) msg;
String topic = publishMessage.variableHeader().topicName();
switch (topic.toLowerCase()) {
case "hardware" :
hardware.messageReceived(state, publishMessage);
break;
}
break;
case PINGREQ :
ctx.writeAndFlush(
MqttMessageFactory.newMessage(msg.fixedHeader(), msg.variableHeader(), null),
ctx.voidPromise());
break;
case DISCONNECT :
log.trace("Got disconnect. Closing...");
ctx.close();
break;
}
}

代码示例来源:origin: blynkkk/blynk-server

session.sendToApps(HARDWARE, msg.variableHeader().packetId(), dashId, deviceId, body);
} else {
log.debug("No active dashboard.");

代码示例来源:origin: andsel/moquette

void processPublish(MqttPublishMessage msg) {
final MqttQoS qos = msg.fixedHeader().qosLevel();
final String username = NettyUtils.userName(channel);
final String topicName = msg.variableHeader().topicName();
final String clientId = getClientId();
LOG.trace("Processing PUBLISH message. CId={}, topic: {}, messageId: {}, qos: {}", clientId, topicName,
msg.variableHeader().packetId(), qos);
ByteBuf payload = msg.payload();
final boolean retain = msg.fixedHeader().isRetain();
break;
case AT_LEAST_ONCE: {
final int messageID = msg.variableHeader().packetId();
postOffice.receivedPublishQos1(this, topic, username, payload, messageID, retain, msg);
break;
final int messageID = msg.variableHeader().packetId();
final Session session = sessionRegistry.retrieve(clientId);
session.receivedPublishQos2(messageID, msg);

代码示例来源:origin: andsel/moquette

case PUBLISH:
MqttPublishMessage publish = (MqttPublishMessage) msg;
LOG.debug("{} PUBLISH <{}> to topics <{}>", direction, clientID, publish.variableHeader().topicName());
break;
case PUBREC:

代码示例来源:origin: andsel/moquette

/**
* First phase of a publish QoS2 protocol, sent by publisher to the broker. Publish to all interested
* subscribers.
*/
void receivedPublishQos2(MQTTConnection connection, MqttPublishMessage mqttPublishMessage, String username) {
LOG.trace("Processing PUBREL message on connection: {}", connection);
final Topic topic = new Topic(mqttPublishMessage.variableHeader().topicName());
final ByteBuf payload = mqttPublishMessage.payload();
final String clientId = connection.getClientId();
if (!authorizator.canWrite(topic, username, clientId)) {
LOG.error("MQTT client is not authorized to publish on topic. CId={}, topic: {}", clientId, topic);
return;
}
publish2Subscribers(payload, topic, EXACTLY_ONCE);
final boolean retained = mqttPublishMessage.fixedHeader().isRetain();
if (retained) {
if (!payload.isReadable()) {
retainedRepository.cleanRetained(topic);
} else {
// before wasn't stored
retainedRepository.retain(topic, mqttPublishMessage);
}
}
String clientID = connection.getClientId();
interceptor.notifyTopicPublished(mqttPublishMessage, clientID, username);
}

代码示例来源:origin: andsel/moquette

/**
* Intended usage is only for embedded versions of the broker, where the hosting application
* want to use the broker to send a publish message. Like normal external publish message but
* with some changes to avoid security check, and the handshake phases for Qos1 and Qos2. It
* also doesn't notifyTopicPublished because using internally the owner should already know
* where it's publishing.
*
* @param msg
* the message to publish
*/
public void internalPublish(MqttPublishMessage msg) {
final MqttQoS qos = msg.fixedHeader().qosLevel();
final Topic topic = new Topic(msg.variableHeader().topicName());
final ByteBuf payload = msg.payload();
LOG.info("Sending internal PUBLISH message Topic={}, qos={}", topic, qos);
publish2Subscribers(payload, topic, qos);
if (!msg.fixedHeader().isRetain()) {
return;
}
if (qos == AT_MOST_ONCE || msg.payload().readableBytes() == 0) {
// QoS == 0 && retain => clean old retained
retainedRepository.cleanRetained(topic);
return;
}
retainedRepository.retain(topic, msg);
}

代码示例来源:origin: apache/rocketmq-externals

String topic = publishMessage.variableHeader().topicName();
if (!subscriptionStore.hasTopic(topic)) {
subscriptionStore.addTopic(topic);
for (Subscription subscription: subscriptionStore.get(publishMessage.variableHeader().topicName())) {
ByteBuf buf = Unpooled.buffer();
byte [] bytes = new byte[publishMessage.payload().readableBytes()];
),
new MqttPublishVariableHeader(
publishMessage.variableHeader().topicName(),
publishMessage.variableHeader().packetId()
),
buf

代码示例来源:origin: apache/rocketmq-externals

public static MqttPubAckMessage getMqttPubackMessage(MqttPublishMessage message) {
MqttFixedHeader fixedHeader = new MqttFixedHeader(
MqttMessageType.PUBACK,
message.fixedHeader().isDup(),
message.fixedHeader().qosLevel(),
message.fixedHeader().isRetain(),
message.fixedHeader().remainingLength()
);
return new MqttPubAckMessage(fixedHeader, MqttMessageIdVariableHeader.from(message.variableHeader().packetId()));
}

代码示例来源:origin: andsel/moquette

private static void assertPublishIsCorrect(String expectedTopic, String expectedContent,
MqttPublishMessage receivedPublish) {
assertNotNull("Expecting a PUBLISH message", receivedPublish);
final String decodedPayload = DebugUtils.payload2Str(receivedPublish.payload());
assertEquals(expectedContent, decodedPayload);
assertEquals(expectedTopic, receivedPublish.variableHeader().topicName());
}

代码示例来源:origin: io.moquette/moquette-broker

public String getTopicName() {
return msg.variableHeader().topicName();
}

代码示例来源:origin: longkerdandy/mithqtt

@Override
public MqttPublishMessage replace(ByteBuf content) {
return new MqttPublishMessage(fixedHeader(), variableHeader(), content);
}

代码示例来源:origin: longkerdandy/mithqtt

public static Message fromMqttMessage(MqttPublishMessage msg, MqttVersion version, String clientId, String userName, String brokerId) {
// forge bytes payload
byte[] bytes = new byte[0];
if (msg.payload() != null && msg.payload().readableBytes() > 0) {
ByteBuf buf = msg.payload().duplicate();
bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
}
return new Message<>(msg.fixedHeader(), new MqttAdditionalHeader(version, clientId, userName, brokerId), msg.variableHeader(), new MqttPublishPayload(bytes));
}

代码示例来源:origin: longkerdandy/mithqtt

@Test
public void testPublishMessage() throws Exception {
final MqttPublishMessage message = createPublishMessage();
ByteBuf byteBuf = MqttEncoder.doEncode(ALLOCATOR, message);
final List out = new LinkedList<>();
mqttDecoder.decode(ctx, byteBuf, out);
assertEquals("Expected one object bout got " + out.size(), 1, out.size());
final MqttPublishMessage decodedMessage = (MqttPublishMessage) out.get(0);
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
validatePublishVariableHeader(message.variableHeader(), decodedMessage.variableHeader());
validatePublishPayload(message.payload(), decodedMessage.payload());
}

代码示例来源:origin: io.moquette/moquette-broker

public static IMessagesStore.StoredMessage asStoredMessage(MqttPublishMessage msg) {
// TODO ugly, too much array copy
ByteBuf payload = msg.payload();
byte[] payloadCOntent= readBytesAndRewind(payload);
IMessagesStore.StoredMessage stored = new IMessagesStore.StoredMessage(payloadContent,
msg.fixedHeader().qosLevel(), msg.variableHeader().topicName());
stored.setRetained(msg.fixedHeader().isRetain());
return stored;
}

推荐阅读
author-avatar
指尖青春_388
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有