package org.wso2.carbon.event.broker;
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.soap.SOAPEnvelope;
import org.wso2.carbon.event.client.broker.BrokerClient;
import org.wso2.carbon.event.client.broker.SimpleMessageReceiver;
public class EventServerSmokeTest {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
//configure for https
System.setProperty("javax.net.ssl.trustStore", "/home/hemapani/playground/events/wso2carbon-3.2.0-SNAPSHOT/resources/security/wso2carbon.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
String topic = "/foo";
//Start the listener
String repoLocation = "/home/hemapani/playground/events/wso2carbon-3.2.0-SNAPSHOT/repository";
String confFile = repoLocation + "/conf/axis2_client.xml";
SimpleMessageReceiver messageReceiver = new SimpleMessageReceiver(repoLocation, confFile,new SimpleMessageReceiver.EventCallback() {
public void mesageReceived(SOAPEnvelope envelope) {
System.out.println("recevied "+ envelope);
}
});
messageReceiver.start();
//Initialize the broker
//BrokerClient brokerClient = new BrokerClient("http://127.0.0.1:9763/services/EventBrokerService");
BrokerClient brokerClient = new BrokerClient("https://127.0.0.1:9443/services/EventBrokerService", "admin", "admin");
//subscribe, notice we set the message sink to listener
String listenerUrl = messageReceiver.getListenerUrl();
System.out.println("listining with "+ listenerUrl);
String subscribtionId = brokerClient.subscribe(topic, listenerUrl);
//String subscribtionId = brokerClient.subscribe(topic, "http://parakum:7777/axis2/services/MessageCollector/receive/");
OMFactory fac = OMAbstractFactory.getOMFactory();
for(int i = 0;i<2;i++){
OMElement ele = fac.createOMElement(new QName("http://wso2.org","foo"+i));
ele.setText("hello"+i);
brokerClient.publish(topic+"/bar", ele);
}
for(int i = 0;i<2;i++){
OMElement ele = fac.createOMElement(new QName("http://wso2.org","foo"+i));
ele.setText("Should not receive"+i);
brokerClient.publish("/bar", ele);
}
brokerClient.unsubscribe(subscribtionId);
Thread.sleep(3000);
//
// BrokerClient brokerClient = new BrokerClient("http://127.0.0.1:5555/services/EventBrokerService");
// SubscriptionDetails[] details = brokerClient.getAllSubscriptions();
//
// for(SubscriptionDetails detail: details){
// System.out.println("Unsubscribed from "+ detail.getSubscriptionId());
// brokerClient.unsubscribe(detail.getSubscriptionId());
// }
}
}