void handlePubComp(int messageId) throws Exception { Pair<Long, Long> ref = session.getState().getOutboundStore().publishComplete(messageId); if (ref != null) { session.getServerSession().individualAcknowledge(managementConsumer.getID(), ref.getA()); } }
void handlePubComp(int messageId) throws Exception { Pair<Long, Long> ref = session.getState().getOutboundStore().publishComplete(messageId); if (ref != null) { session.getServerSession().individualAcknowledge(managementConsumer.getID(), ref.getA()); } }
void handlePubAck(int messageId) throws Exception { try { Pair<Long, Long> ref = outboundStore.publishAckd(messageId); if (ref != null) { session.getServerSession().individualAcknowledge(ref.getB(), ref.getA()); } } catch (ActiveMQIllegalStateException e) { log.warn("MQTT Client(" + session.getSessionState().getClientId() + ") attempted to Ack already Ack'd message"); } }
void handlePubAck(int messageId) throws Exception { try { Pair<Long, Long> ref = outboundStore.publishAckd(messageId); if (ref != null) { session.getServerSession().individualAcknowledge(ref.getB(), ref.getA()); } } catch (ActiveMQIllegalStateException e) { log.warn("MQTT Client(" + session.getSessionState().getClientId() + ") attempted to Ack already Ack'd message"); } }
void handlePubRec(int messageId) throws Exception { try { Pair<Long, Long> ref = outboundStore.publishReceived(messageId); if (ref != null) { Message m = MQTTUtil.createPubRelMessage(session, getManagementAddress(), messageId); session.getServerSession().send(m, true); session.getServerSession().individualAcknowledge(ref.getB(), ref.getA()); } else { session.getProtocolHandler().sendPubRel(messageId); } } catch (ActiveMQIllegalStateException e) { log.warn("MQTT Client(" + session.getSessionState().getClientId() + ") attempted to Ack already Ack'd message"); } }
void handlePubRec(int messageId) throws Exception { try { Pair<Long, Long> ref = outboundStore.publishReceived(messageId); if (ref != null) { Message m = MQTTUtil.createPubRelMessage(session, getManagementAddress(), messageId); session.getServerSession().send(m, true); session.getServerSession().individualAcknowledge(ref.getB(), ref.getA()); } else { session.getProtocolHandler().sendPubRel(messageId); } } catch (ActiveMQIllegalStateException e) { log.warn("MQTT Client(" + session.getSessionState().getClientId() + ") attempted to Ack already Ack'd message"); } }
/** * Since MQTT Subscriptions can over lap; a client may receive the same message twice. When this happens the client * returns a PubRec or PubAck with ID. But we need to know which consumer to ack, since we only have the ID to go on we * are not able to decide which consumer to ack. Instead we send MQTT messages with different IDs and store a reference * to original ID and consumer in the Session state. This way we can look up the consumer Id and the message Id from * the PubAck or PubRec message id. * */ protected void sendMessage(ICoreMessage message, ServerConsumer consumer, int deliveryCount) throws Exception { // This is to allow retries of PubRel. if (isManagementConsumer(consumer)) { sendPubRelMessage(message); } else { int qos = decideQoS(message, consumer); if (qos == 0) { sendServerMessage((int) message.getMessageID(), message, deliveryCount, qos); session.getServerSession().individualAcknowledge(consumer.getID(), message.getMessageID()); } else if (qos == 1 || qos == 2) { int mqttid = outboundStore.generateMqttId(message.getMessageID(), consumer.getID()); outboundStore.publish(mqttid, message.getMessageID(), consumer.getID()); sendServerMessage(mqttid, message, deliveryCount, qos); } else { // Client must have disconnected and it's Subscription QoS cleared consumer.individualCancel(message.getMessageID(), false); } } }
/** * Since MQTT Subscriptions can over lap; a client may receive the same message twice. When this happens the client * returns a PubRec or PubAck with ID. But we need to know which consumer to ack, since we only have the ID to go on we * are not able to decide which consumer to ack. Instead we send MQTT messages with different IDs and store a reference * to original ID and consumer in the Session state. This way we can look up the consumer Id and the message Id from * the PubAck or PubRec message id. * */ protected void sendMessage(ICoreMessage message, ServerConsumer consumer, int deliveryCount) throws Exception { // This is to allow retries of PubRel. if (isManagementConsumer(consumer)) { sendPubRelMessage(message); } else { int qos = decideQoS(message, consumer); if (qos == 0) { sendServerMessage((int) message.getMessageID(), message, deliveryCount, qos); session.getServerSession().individualAcknowledge(consumer.getID(), message.getMessageID()); } else if (qos == 1 || qos == 2) { int mqttid = outboundStore.generateMqttId(message.getMessageID(), consumer.getID()); outboundStore.publish(mqttid, message.getMessageID(), consumer.getID()); sendServerMessage(mqttid, message, deliveryCount, qos); } else { // Client must have disconnected and it's Subscription QoS cleared consumer.individualCancel(message.getMessageID(), false); } } }