private AsyncDataPublisher createDataPublisher(BrokerConfiguration brokerConfiguration) { if (agent == null) { agent = BrokerServiceValueHolder.getAgent(); } AsyncDataPublisher dataPublisher; Map<String, String> properties = brokerConfiguration.getProperties(); if (null != properties.get(BrokerConstants.BROKER_CONF_AGENT_PROP_AUTHENTICATOR_URL) && properties.get(BrokerConstants.BROKER_CONF_AGENT_PROP_AUTHENTICATOR_URL).length() > 0) { dataPublisher = new AsyncDataPublisher( properties.get(BrokerConstants.BROKER_CONF_AGENT_PROP_AUTHENTICATOR_URL), properties.get(BrokerConstants.BROKER_CONF_AGENT_PROP_RECEIVER_URL), properties.get(BrokerConstants.BROKER_CONF_AGENT_PROP_USER_NAME), properties.get(BrokerConstants.BROKER_CONF_AGENT_PROP_PASSWORD), agent); } else { dataPublisher = new AsyncDataPublisher( properties.get(BrokerConstants.BROKER_CONF_AGENT_PROP_RECEIVER_URL), properties.get(BrokerConstants.BROKER_CONF_AGENT_PROP_USER_NAME), properties.get(BrokerConstants.BROKER_CONF_AGENT_PROP_PASSWORD), agent); } return dataPublisher; }
public void publish(String topicName, Object message, BrokerConfiguration brokerConfiguration) throws BrokerEventProcessingException { EventBroker eventBroker = BrokerServiceValueHolder.getEventBroker(); Message eventMessage = new Message(); eventMessage.setMessage(((OMElement) message)); try { eventBroker.publishRobust(eventMessage, topicName); } catch (EventBrokerException e) { throw new BrokerEventProcessingException("Can not publish the to local broker ", e); } }
private AgentBrokerType() { this.brokerTypeDto = new BrokerTypeDto(); this.brokerTypeDto.setName(BrokerConstants.BROKER_TYPE_AGENT); ResourceBundle resourceBundle = ResourceBundle.getBundle("org.wso2.carbon.broker.core.i18n.Resources", Locale.getDefault()); // set receiver url broker Property ipProperty = new Property(BrokerConstants.BROKER_CONF_AGENT_PROP_RECEIVER_URL); ipProperty.setDisplayName( resourceBundle.getString(BrokerConstants.BROKER_CONF_AGENT_PROP_RECEIVER_URL)); ipProperty.setRequired(true); this.brokerTypeDto.addProperty(ipProperty); // set authenticator url of broker Property authenticatorIpProperty = new Property(BrokerConstants.BROKER_CONF_AGENT_PROP_AUTHENTICATOR_URL); authenticatorIpProperty.setDisplayName( resourceBundle.getString(BrokerConstants.BROKER_CONF_AGENT_PROP_AUTHENTICATOR_URL)); authenticatorIpProperty.setRequired(false); this.brokerTypeDto.addProperty(authenticatorIpProperty); // set connection user name as property Property userNameProperty = new Property(BrokerConstants.BROKER_CONF_AGENT_PROP_USER_NAME); userNameProperty.setRequired(true); userNameProperty.setDisplayName( resourceBundle.getString(BrokerConstants.BROKER_CONF_AGENT_PROP_USER_NAME)); this.brokerTypeDto.addProperty(userNameProperty); // set connection password as property Property passwordProperty = new Property(BrokerConstants.BROKER_CONF_AGENT_PROP_PASSWORD); passwordProperty.setRequired(true); passwordProperty.setSecured(true); passwordProperty.setDisplayName( resourceBundle.getString(BrokerConstants.BROKER_CONF_AGENT_PROP_PASSWORD)); this.brokerTypeDto.addProperty(passwordProperty); BrokerServiceValueHolder.getDataBridgeSubscriberService().subscribe(new AgentBrokerCallback()); }
@Override public void receive(List<Event> events, Credentials credentials) { for (Event event : events) { Map<String, BrokerListener> brokerListeners = streamIdBrokerListenerMap.get(event.getStreamId()); if (brokerListeners == null) { try { definedStream( BrokerServiceValueHolder.getDataBridgeSubscriberService() .getStreamDefinition(credentials, event.getStreamId()), credentials); } catch (StreamDefinitionNotFoundException e) { log.error("No Stream definition store found for the event " + event.getStreamId(), e); return; } catch (StreamDefinitionStoreException e) { log.error( "No Stream definition store found when checking stream definition for " + event.getStreamId(), e); return; } brokerListeners = streamIdBrokerListenerMap.get(event.getStreamId()); if (brokerListeners == null) { log.error("No broker listeners for " + event.getStreamId()); return; } } for (BrokerListener brokerListener : brokerListeners.values()) { try { brokerListener.onEvent(event); } catch (BrokerEventProcessingException e) { log.error( "Cannot send event to a brokerListener subscribed to " + event.getStreamId(), e); } } } }