@Override public void sendEvent(JetstreamEvent event) throws EventException { String key = JetstreamReservedKeys.EventReplayTopic.toString(); if (event.containsKey(key)) { String retryTopic = (String) event.get(key); if (retryTopic != null && retryTopic.length() != 0) { retryTopic = "Replay-" + retryTopic.replaceAll("/", "-"); event.setForwardingTopics(new String[] {retryTopic}); } } super.sendEvent(event); }
@Override public TestRecord transform(JetstreamEvent event) { TestRecord record = new TestRecord(); record.setKey1((String) event.get("key1")); record.setKey2((String) event.get("key2")); return record; }
/** * @param event * @param code * @param msg */ private void sendToAdviceListener(JetstreamEvent event, RetryEventCode code, String msg) { try { if (getAdviceListener() != null) { if (event.containsKey(JetstreamReservedKeys.RetryCount.toString())) { Integer retryCount = (Integer) event.get(JetstreamReservedKeys.RetryCount.toString()); if (retryCount > getRetryCount()) { LOGGER.info("Unable to deliver this event so dropping it.." + event.getEventId()); m_totalEventsDropped.increment(); return; } } getAdviceListener().retry(event, code, msg); incrementAdviceListenerCount(); } } catch (Throwable e) { m_errors.registerError(e); LOGGER.debug(e.getLocalizedMessage()); } }
private JetstreamEvent constructTEventHolder(JetstreamEvent event) { if (event != null) { JetstreamEvent holderEvent = new JetstreamEvent(); holderEvent.put(JetstreamReservedKeys.JetstreamEventHolder.toString(), event); holderEvent.put(JetstreamReservedKeys.EventType.toString(), event.getEventType()); // insert source application to DTE String eventSource = null; if (event.get(JetstreamReservedKeys.EventSource.toString()) != null) { eventSource = (String) event.get(JetstreamReservedKeys.EventSource.toString()); } else { eventSource = JetstreamApplication.getInstance().getApplicationInformation().getApplicationName(); } holderEvent.put(JetstreamReservedKeys.EventSource.toString(), eventSource); return holderEvent; } return event; }
/* * (non-Javadoc) * * @see com.ebay.jetstream.event.EventSink#sendEvent(com.ebay.jetstream.event.JetstreamEvent) */ public void sendEvent(JetstreamEvent event) throws EventException { incrementEventRecievedCounter(); List<JetstreamTopic> publishingTopics = m_address.getChannelJetstreamTopics(); String[] forwardingTopics = event.getForwardingTopics(); for (JetstreamTopic topic : publishingTopics) { if (forwardingTopics != null) { boolean bFound = false; String strSeekName = topic.getTopicName(); for (String strTopic : forwardingTopics) { if (strTopic.equals(strSeekName)) { bFound = true; break; } } if (!bFound) continue; } if (LOGGER.isDebugEnabled()) { LOGGER.debug( "eventSource=" + getBeanName() + "&eventId = " + event.getEventId() + "&topic=" + topic); } Any any = null; if (isConstructEventHolder()) { JetstreamEvent holderEvent = constructTEventHolder(event); any = new Any(holderEvent); } else { any = new Any(event); } any.setPriority(JetstreamMessage.HI_PRIORITY); if (event.containsKey(affinityKey)) { Object affkey = event.get(affinityKey); if (affkey == null) { incrementEventDroppedCounter(); if (LOGGER.isDebugEnabled()) LOGGER.debug(" Affinity Key passed in is null"); return; } any.setAffinityKey(affkey); if (LOGGER.isDebugEnabled()) { LOGGER.debug( "sending on topic - " + topic.getTopicName() + " " + ": Affinity Key = " + event.get(affinityKey).toString() + " EVENT - " + event.toString()); } } // we assume that caller will not set affinity key and bcast flag at the same time // if affinity key is set it will override bcast if (event.getMetaData(bcastMsg) != null) { any.setBroadcastMessage(Boolean.parseBoolean((String) event.getMetaData(bcastMsg))); if (LOGGER.isDebugEnabled()) { LOGGER.debug( "sending on topic - " + topic.getTopicName() + " " + ": BroadCast Key = " + event.getMetaData(bcastMsg).toString() + " EVENT - " + event.toString()); } } try { MessageService.getInstance().publish(topic, any); setLastEvent(event); incrementEventSentCounter(); } catch (MessageServiceException mse) { m_errors.registerError(mse); String errMsg = "Error Publishing Message for Topic - " + topic.getTopicName(); // NOPMD errMsg += " - "; errMsg += mse.getMessage(); if (LOGGER.isWarnEnabled()) { LOGGER.warn(errMsg); } sendToAdviceListener(event, RetryEventCode.UNKNOWN, errMsg); incrementEventDroppedCounter(); if (mse.getError() == MessageServiceException.BUFFER_FULL && !m_alarmRaised.get()) { setTopicAlarmState(topic.getRootContext()); if (areAllContextsInAlarmCondition()) { getAlarmListener().alarm(ChannelAlarm.OVERRUN); postAlert("MessageService Buffer full condition - ", AlertStrength.YELLOW); LOGGER.info("Outbound Messaging Channel raising alarm"); m_alarmRaised.set(true); incrementAlarmsRaisedCounter(); } } } catch (Throwable t) { m_errors.registerError(t); String errMsg = "Error Publishing Message for Topic - " + topic.getTopicName(); errMsg += " - "; errMsg += t.getMessage(); sendToAdviceListener(event, RetryEventCode.UNKNOWN, errMsg); incrementEventDroppedCounter(); if (LOGGER.isDebugEnabled()) LOGGER.debug(errMsg); } } }
/* * (non-Javadoc) * * @see com.ebay.jetstream.messaging.JetstreamMessageListener#onMessage(com.ebay.jetstream.messaging.JetstreamMessage) */ public void onMessage(JetstreamMessage m) { if (m instanceof AdvisoryMessage) { AdvisoryMessage advise = (AdvisoryMessage) m; if (advise.isStopSending() && matchesMyPublishingContexts(advise.getAdvisoryTopic().getRootContext())) { LOGGER.warn("Outbound Messaging Channel raising alarm"); setTopicAlarmState(advise.getAdvisoryTopic().getRootContext()); incrementAlarmsRaisedCounter(); if (areAllContextsInAlarmCondition()) { m_alarmRaised.set(true); getAlarmListener().alarm(ChannelAlarm.OVERRUN); postAlert("All Contexts in Alarm Condition - ", AlertStrength.ORANGE); } } else if (advise.isResumeSending() && matchesMyPublishingContexts(advise.getAdvisoryTopic().getRootContext())) { LOGGER.info( "Outbound Messaging Channel clearing alarm for topic-> " + advise.getAdvisoryTopic().getRootContext()); resetTopicAlarmState(advise.getAdvisoryTopic().getRootContext()); if (!areAllContextsInAlarmCondition()) { m_alarmRaised.set(false); getAlarmListener().alarm(ChannelAlarm.CLEAR); postAlert("Alarm Condition Cleared - ", AlertStrength.YELLOW); incrementAlarmsClearedCounter(); } } else if (advise.isResendMessage()) { JetstreamEvent evt = (JetstreamEvent) ((Any) ((AdvisoryMessage) m).getUndeliveredMsg()).getObject(); try { evt = evt.clone(); } catch (CloneNotSupportedException e) { m_errors.registerError(e); LOGGER.debug("Failed to clone event : Exception = " + e.getLocalizedMessage()); this.incrementEventDroppedCounter(); return; } List<String> topics = m_address.getChannelTopics(); String topic = ((AdvisoryMessage) m).getAdvisoryTopic().toString(); // Fix issue when multiple OMCs subscribe different topics under same context. // Each OMC will receive broadcast advisory events. if (topic == null || topics.contains(topic)) { evt.put(JetstreamReservedKeys.EventReplayTopic.toString(), topic); Integer retryCount = 1; if (evt != null) { if (evt.containsKey(JetstreamReservedKeys.RetryCount.toString())) { retryCount = (Integer) evt.get(JetstreamReservedKeys.RetryCount.toString()); retryCount++; } evt.put(JetstreamReservedKeys.RetryCount.toString(), retryCount); sendToAdviceListener( evt, RetryEventCode.MSG_RETRY, AdvisoryCode.RESEND_MESSAGE.toString()); incrementRetryAdvisoryEvents(); } } } } }