public void testSendingSameStreamDefinitions() throws MalformedURLException, AuthenticationException, TransportException, AgentException, UndefinedEventTypeException, DifferentStreamDefinitionAlreadyDefinedException, InterruptedException, DataBridgeException, MalformedStreamDefinitionException, StreamDefinitionException { TestServer testServer = new TestServer(); testServer.start(7614); KeyStoreUtil.setTrustStoreParams(); Thread.sleep(2000); // according to the convention the authentication port will be 7611+100= 7711 and its host will // be the same DataPublisher dataPublisher = new DataPublisher("tcp://localhost:7614", "admin", "admin"); String id1 = dataPublisher.defineStream( "{" + " 'name':'org.wso2.esb.MediatorStatistics'," + " 'version':'2.3.0'," + " 'nickName': 'Stock Quote Information'," + " 'description': 'Some Desc'," + " 'tags':['foo', 'bar']," + " 'metaData':[" + " {'name':'ipAdd','type':'STRING'}" + " ]," + " 'payloadData':[" + " {'name':'symbol','type':'STRING'}," + " {'name':'price','type':'DOUBLE'}," + " {'name':'volume','type':'INT'}," + " {'name':'max','type':'DOUBLE'}," + " {'name':'min','type':'Double'}" + " ]" + "}"); String id2 = dataPublisher.defineStream( "{" + " 'name':'org.wso2.esb.MediatorStatistics'," + " 'version':'2.3.0'," + " 'nickName': 'Stock Quote Information'," + " 'description': 'Some Desc'," + " 'tags':['foo', 'bar']," + " 'metaData':[" + " {'name':'ipAdd','type':'STRING'}" + " ]," + " 'payloadData':[" + " {'name':'symbol','type':'STRING'}," + " {'name':'price','type':'DOUBLE'}," + " {'name':'volume','type':'INT'}," + " {'name':'max','type':'DOUBLE'}," + " {'name':'min','type':'Double'}" + " ]" + "}"); Assert.assertEquals(id1, id2); // In this case correlation data is null dataPublisher.publish( id1, new Object[] {"127.0.0.1"}, null, new Object[] {"IBM", 96.8, 300, 120.6, 70.4}); dataPublisher.stop(); testServer.stop(); }
public void testSendingTwoDifferentStreamDefinitionsWithSameStreamId() throws MalformedURLException, AuthenticationException, TransportException, AgentException, UndefinedEventTypeException, InterruptedException, DataBridgeException, MalformedStreamDefinitionException, StreamDefinitionException, DifferentStreamDefinitionAlreadyDefinedException { TestServer testServer = new TestServer(); testServer.start(7617); KeyStoreUtil.setTrustStoreParams(); Thread.sleep(2000); // according to the convention the authentication port will be 7611+100= 7711 and its host will // be the same DataPublisher dataPublisher = new DataPublisher("tcp://localhost:7617", "admin", "admin"); dataPublisher.defineStream( "{" + " 'name':'org.wso2.esb.MediatorStatistics3'," + " 'version':'2.3.0'," + " 'nickName': 'Stock Quote Information'," + " 'description': 'Some Desc'," + " 'tags':['foo', 'bar']," + " 'metaData':[" + " {'name':'ipAdd','type':'STRING'}" + " ]," + " 'payloadData':[" + " {'name':'symbol','type':'STRING'}," + " {'name':'price','type':'DOUBLE'}," + " {'name':'volume','type':'INT'}," + " {'name':'max','type':'DOUBLE'}," + " {'name':'min','type':'Double'}" + " ]" + "}"); Boolean exceptionOccurred = false; try { dataPublisher.defineStream( "{" + " 'name':'org.wso2.esb.MediatorStatistics3'," + " 'version':'2.3.0'," + " 'nickName': 'Stock Quote Information'," + " 'description': 'Some Desc'," + " 'tags':['foo', 'bar']," + " 'metaData':[" + " {'name':'ipAdd','type':'STRING'}" + " ]," + " 'payloadData':[" + " {'name':'symbol','type':'STRING'}," + " {'name':'price','type':'DOUBLE'}," + " {'name':'volume','type':'INT'}," + " {'name':'min','type':'Double'}" + " ]" + "}"); } catch (DifferentStreamDefinitionAlreadyDefinedException e) { exceptionOccurred = true; } Assert.assertTrue(exceptionOccurred); dataPublisher.stop(); testServer.stop(); }
public static void main(String[] args) throws AgentException, MalformedStreamDefinitionException, StreamDefinitionException, DifferentStreamDefinitionAlreadyDefinedException, MalformedURLException, AuthenticationException, NoStreamDefinitionExistException, TransportException, SocketException, org.wso2.carbon.databridge.commons.exception.AuthenticationException { System.out.println("Starting Activity Monitoring Sample"); KeyStoreUtil.setTrustStoreParams(); String host = args[0]; String port = args[1]; String username = args[2]; String password = args[3]; int events = Integer.parseInt(args[4]); // create data publisher DataPublisher dataPublisher = new DataPublisher("tcp://" + host + ":" + port, username, password); String streamId = null; try { streamId = dataPublisher.findStream(ACTIVITY_MONITORING_STREAM, VERSION); System.out.println("Stream already defined"); } catch (NoStreamDefinitionExistException e) { streamId = dataPublisher.defineStream( "{" + " 'name':'" + ACTIVITY_MONITORING_STREAM + "'," + " 'version':'" + VERSION + "'," + " 'nickName': 'Activity_Monitoring'," + " 'description': 'A sample for Activity Monitoring'," + " 'metaData':[" + " {'name':'character_set_encoding','type':'STRING'}," + " {'name':'host','type':'STRING'}," + " {'name':'http_method','type':'STRING'}," + " {'name':'message_type','type':'STRING'}," + " {'name':'remote_address','type':'STRING'}," + " {'name':'remote_host','type':'STRING'}," + " {'name':'service_prefix','type':'STRING'}," + " {'name':'tenant_id','type':'INT'}," + " {'name':'transport_in_url','type':'STRING'}" + " ]," + " 'correlationData':[" + " {'name':'bam_activity_id','type':'STRING'}" + " ]," + " 'payloadData':[" + " {'name':'soap_body','type':'STRING'}," + " {'name':'soap_header','type':'STRING'}," + " {'name':'message_direction','type':'STRING'}," + " {'name':'message_id','type':'STRING'}," + " {'name':'operation_name','type':'STRING'}," + " {'name':'service_name','type':'STRING'}," + " {'name':'timestamp','type':'LONG'}" + " ]" + "}"); // //Define event stream } // Publish event for a valid stream if (!streamId.isEmpty()) { System.out.println("Stream ID: " + streamId); for (int i = 0; i < events; i++) { publishEvents(dataPublisher, streamId, i); System.out.println("Events published : " + (i + 1)); } try { Thread.sleep(2000); } catch (InterruptedException e) { } dataPublisher.stop(); } }
public static void main(String[] args) throws AgentException, MalformedStreamDefinitionException, StreamDefinitionException, DifferentStreamDefinitionAlreadyDefinedException, MalformedURLException, AuthenticationException, NoStreamDefinitionExistException, TransportException, SocketException, org.wso2.carbon.databridge.commons.exception.AuthenticationException { System.out.println("Starting Mediator Statistic Sample"); AgentConfiguration agentConfiguration = new AgentConfiguration(); String currentDir = System.getProperty("user.dir"); System.setProperty( "javax.net.ssl.trustStore", currentDir + "/src/main/resources/client-truststore.jks"); System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon"); Agent agent = new Agent(agentConfiguration); String host; if (getLocalAddress() != null) { host = getLocalAddress().getHostAddress(); } else { host = "localhost"; // Defaults to localhost } String url = getProperty("url", "tcp://" + host + ":" + "7611"); String username = getProperty("username", "admin"); String password = getProperty("password", "admin"); // create data publisher DataPublisher dataPublisher = new DataPublisher(url, username, password, agent); String streamId = null; try { streamId = dataPublisher.findStream(MEDIATOR_STATISTICS_STREAM, VERSION); System.out.println("Stream already defined"); } catch (NoStreamDefinitionExistException e) { streamId = dataPublisher.defineStream( "{" + " 'name':'" + MEDIATOR_STATISTICS_STREAM + "'," + " 'version':'" + VERSION + "'," + " 'nickName': 'MediationStatsDataAgent'," + " 'description': 'A sample for Mediator Statistics'," + " 'metaData':[" + " {'name':'host','type':'STRING'}" + " ]," + " 'payloadData':[" + " {'name':'direction','type':'STRING'}," + " {'name':'timestamp','type':'LONG'}," + " {'name':'resource_id','type':'STRING'}," + " {'name':'stats_type','type':'STRING'}," + " {'name':'max_processing_time','type':'LONG'}," + " {'name':'avg_processing_time','type':'DOUBLE'}," + " {'name':'min_processing_time','type':'LONG'}," + " {'name':'fault_count','type':'INT'}," + " {'name':'count','type':'INT'}" + " ]" + "}"); } // Publish event for a valid stream if (!streamId.isEmpty()) { System.out.println("Stream ID: " + streamId); for (int i = 0; i < 3000; i++) { publishEvents(dataPublisher, streamId); System.out.println("Events published : " + (i + 1)); if ((i % 100) == 0) { try { Thread.sleep(1000); } catch (InterruptedException e) { // Do nothing. Just add time buffer } } } try { Thread.sleep(2000); } catch (InterruptedException e) { } dataPublisher.stop(); } }