public void addSubscription(final Topic topic, final NotificationParams params) { // If listener is already subscribe to topic, override its notification params subscriptions.put(topic.getTopic(), params); }
private boolean unsubscribeMonitor() { boolean unsubscriptionDone = true; try { LOGGER.debug("Removing subscription from topic {}", monitorTopic.getTopic()); listenerContainer.removeMessageListener(monitorListener, monitorTopic); } catch (final RedisInvalidSubscriptionException rise) { LOGGER.error("An error occurred while unsubscribing from topic {}", monitorTopic.getTopic(), rise); unsubscriptionDone = false; } return unsubscriptionDone; }
private boolean subscribeMonitor() { boolean subscriptionDone = true; try { LOGGER.debug("Adding subscription to topic {}", monitorTopic.getTopic()); listenerContainer.addMessageListener(monitorListener, monitorTopic); } catch (final RedisInvalidSubscriptionException rise) { LOGGER.error("An error occurred while subscribing to topic {}", monitorTopic.getTopic(), rise); subscriptionDone = false; } return subscriptionDone; }
public void publishPing() { redisTemplate.convertAndSend(monitorTopic.getTopic(), "PING SUBSCRIPTION"); lock.lock(); try { countPendingEvents++; } finally { lock.unlock(); } }
private void removeSubscription(final Subscription subscription) { final Topic topic = ChannelUtils.getChannel(subscription); LOGGER.debug("Removing subscription to channel {} for listener {} ", topic.getTopic(), subscription.getSourceEntityId()); final MessageListenerImpl listener = listeners.get(subscription.getSourceEntityId()); if (listener != null) { listenerContainer.removeMessageListener(listener, topic); listener.removeSubscription(topic); } // Finally, the subscription to the topic is removed from Redis jedisTemplate.hDel(keysBuilder.getSubscriptionKey(subscription.getSourceEntityId()), topic.getTopic()); LOGGER.debug("Removed subscription from listener {} to channel {}", subscription.getSourceEntityId(), topic.getTopic()); }
private void activateSubscription(final String listenerName, final Topic topic, final NotificationParams notificationParams) { MessageListenerImpl listener = listeners.get(listenerName); if (listener == null) { listener = addNewListener(listenerName); } LOGGER.info("Subscribing listener {} to channel {}", listener.getName(), topic.getTopic()); listenerContainer.addMessageListener(listener, topic); listener.addSubscription(topic, notificationParams); }
private void publish(final AlarmInputMessage message) { LOGGER.debug("Publish alarm event message [{}] associated with alert [{}]", message.getMessage(), message.getAlertId()); final Topic topic = ChannelUtils.buildTopic(PubSubChannelPrefix.alarm, message.getAlertId()); jedisTemplate.publish(topic.getTopic(), PublishMessageUtils.buildContentToPublish(message, topic)); }
private void publish(final OrderInputMessage message) { LOGGER.debug("Publish order event [{}] related to provider [{}] and sensor [{}]", message.getOrder(), message.getProviderId(), message.getSensorId()); final Topic topic = ChannelUtils.buildTopic(PubSubChannelPrefix.order, message.getProviderId(), message.getSensorId()); jedisTemplate.publish(topic.getTopic(), PublishMessageUtils.buildContentToPublish(message, topic)); LOGGER.debug("Order published"); } }
private void publishSensorData(final Observation data) { final Topic topic = ChannelUtils.buildTopic(PubSubChannelPrefix.data, data.getProvider(), data.getSensor()); jedisTemplate.publish(topic.getTopic(), PublishMessageUtils.buildContentToPublish(data, topic)); }
@Override public void subscribe(final Subscription subscription) { // The first step is to validate that the resource to which the subscription refers exists in // Sentilo. Otherwise an error is thrown checkTargetResourceState(subscription); // Al subscribirse, no sólo se debe habilitar el listener correspondiente, sino que tb se debe // persistir en Redis la subscripcion para la entidad de turno. De esta manera se podrán // iniciar los listeners asociados a las subscripciones ya existentes cuando se arranque // este modulo. // Estos registros en Redis serán del tipo Hash y habrá uno para cada entidad. // Es decir, para cada entidad que este subscrita a algun canal tendremos en Redis // una Hash con key igual a subs:<entityId> y N entradas <field, value> donde: // - field: cada campo de la hash corresponderá a una subscripcion , por lo que el nombre del // campo identificará el canal al cual se está subscrito <event_type>/element_id, donde // element_id es el identificador del recurso al cual se esta subscrito. // - value: el value del campo contiene la informacion necesaria para realizar la notificacion // via HTTP Callback (estos datos son el endpoint, la secretKey a utilizar, politica de // reintentos, ...) final Topic topic = ChannelUtils.getChannel(subscription); // Habilitamos listener activateSubscription(subscription.getSourceEntityId(), topic, subscription.getNotificationParams()); // Persistimos en Redis la subscripcion jedisTemplate.hSet(keysBuilder.getSubscriptionKey(subscription.getSourceEntityId()), topic.getTopic(), converter.marshal(subscription.getNotificationParams())); LOGGER.info("Listener {} subscribed to channel {}", subscription.getSourceEntityId(), topic.getTopic()); }