Search in sources :

Example 6 with MqttFixedHeader

use of com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttFixedHeader in project swiftmq-ce by iitsoftware.

the class MqttEncoder method encodeMessageWithOnlySingleByteFixedHeaderAndMessageId.

private static com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf encodeMessageWithOnlySingleByteFixedHeaderAndMessageId(MqttMessage message) {
    MqttFixedHeader mqttFixedHeader = message.fixedHeader();
    MqttMessageIdVariableHeader variableHeader = (MqttMessageIdVariableHeader) message.variableHeader();
    int msgId = variableHeader.messageId();
    // variable part only has a message id
    int variableHeaderBufferSize = 2;
    int fixedHeaderBufferSize = 1 + getVariableLengthInt(variableHeaderBufferSize);
    com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf buf = new com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf(fixedHeaderBufferSize + variableHeaderBufferSize);
    buf.writeByte(getFixedHeaderByte1(mqttFixedHeader));
    writeVariableLengthInt(buf, variableHeaderBufferSize);
    buf.writeShort(msgId);
    return buf;
}
Also used : ByteBuf(com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf) ByteBuf(com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)

Example 7 with MqttFixedHeader

use of com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttFixedHeader in project swiftmq-ce by iitsoftware.

the class MqttEncoder method encodePublishMessage.

private static com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf encodePublishMessage(MqttPublishMessage message) {
    MqttFixedHeader mqttFixedHeader = message.fixedHeader();
    MqttPublishVariableHeader variableHeader = message.variableHeader();
    com.swiftmq.impl.mqtt.v311.netty.buffer.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);
    com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf buf = new com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf(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;
}
Also used : ByteBuf(com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf) ByteBuf(com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)

Example 8 with MqttFixedHeader

use of com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttFixedHeader in project swiftmq-ce by iitsoftware.

the class MqttEncoder method encodeMessageWithOnlySingleByteFixedHeader.

private static com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf encodeMessageWithOnlySingleByteFixedHeader(MqttMessage message) {
    MqttFixedHeader mqttFixedHeader = message.fixedHeader();
    com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf buf = new com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf(2);
    buf.writeByte(getFixedHeaderByte1(mqttFixedHeader));
    buf.writeByte(0);
    return buf;
}
Also used : ByteBuf(com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf) ByteBuf(com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)

Example 9 with MqttFixedHeader

use of com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttFixedHeader in project swiftmq-ce by iitsoftware.

the class Producer method send.

public void send(MqttPublishMessage mqttPublishMessage) throws Exception {
    MqttFixedHeader fixedHeader = mqttPublishMessage.fixedHeader();
    ByteBuf payload = mqttPublishMessage.payload();
    BytesMessageImpl bytesMessage = new BytesMessageImpl();
    bytesMessage.setJMSDestination(topic);
    bytesMessage.setJMSTimestamp(System.currentTimeMillis());
    bytesMessage.setJMSMessageID(session.getMqttConnection().nextId());
    bytesMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
    bytesMessage.setStringProperty(MessageImpl.PROP_USER_ID, session.getMqttConnection().getActiveLogin().getUserName());
    bytesMessage.setStringProperty(MessageImpl.PROP_CLIENT_ID, session.getClientId());
    if (fixedHeader.isDup())
        bytesMessage.setBooleanProperty(MessageImpl.PROP_DOUBT_DUPLICATE, true);
    bytesMessage.setIntProperty(PROP_QOS, fixedHeader.qosLevel().value());
    payload.reset();
    byte[] b = new byte[payload.size()];
    payload.readBytes(b);
    bytesMessage.writeBytes(b);
    transaction = sender.createTransaction();
    transaction.putMessage(bytesMessage);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", sent: " + bytesMessage);
}
Also used : MqttFixedHeader(com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttFixedHeader) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) ByteBuf(com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)

Aggregations

ByteBuf (com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)9 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)2 MQTTSession (com.swiftmq.impl.mqtt.session.MQTTSession)1 DecoderException (com.swiftmq.impl.mqtt.v311.netty.handler.codec.DecoderException)1 MqttFixedHeader (com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttFixedHeader)1 EntityAddException (com.swiftmq.mgmt.EntityAddException)1 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)1 ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)1 QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)1