use of io.fabric8.gateway.ServiceMap in project fabric8 by jboss-fuse.
the class FabricMQGateway method addGateway.
protected TcpGateway addGateway(List<TcpGateway> gateways, Vertx vertx, ServiceMap serviceMap, String protocolName, boolean enabled, int listenPort, LoadBalancer pathLoadBalancer, LoadBalancer serviceLoadBalancer) {
if (enabled) {
TcpGatewayHandler handler = new TcpGatewayHandler(vertx, serviceMap, protocolName, pathLoadBalancer, serviceLoadBalancer);
TcpGateway gateway = new TcpGateway(vertx, serviceMap, listenPort, protocolName, handler);
if (Strings.isNotBlank(host)) {
gateway.setHost(host);
}
gateways.add(gateway);
return gateway;
} else {
return null;
}
}
use of io.fabric8.gateway.ServiceMap in project fabric8 by jboss-fuse.
the class FabricMQGateway method createListener.
protected GatewayServiceTreeCache createListener() {
String zkPath = getZooKeeperPath();
// TODO we should discover the broker group configuration here using the same
// mq-create / mq-client profiles so that we only listen to a subset of the available brokers here?
ServiceMap serviceMap = new ServiceMap();
VertxService vertxService = getVertxService();
Vertx vertx = vertxService.getVertx();
CuratorFramework curator = getCurator();
LoadBalancer pathLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
LOG.info("activating MQ mapping ZooKeeper path: " + zkPath + " host: " + host + " with load balancer: " + pathLoadBalancer);
List<TcpGateway> gateways = new ArrayList<TcpGateway>();
addGateway(gateways, vertx, serviceMap, "tcp", isOpenWireEnabled(), getOpenWirePort(), pathLoadBalancer, serviceLoadBalancer);
addGateway(gateways, vertx, serviceMap, "stomp", isStompEnabled(), getStompPort(), pathLoadBalancer, serviceLoadBalancer);
addGateway(gateways, vertx, serviceMap, "amqp", isAmqpEnabled(), getAmqpPort(), pathLoadBalancer, serviceLoadBalancer);
addGateway(gateways, vertx, serviceMap, "mqtt", isMqttEnabled(), getMqttPort(), pathLoadBalancer, serviceLoadBalancer);
addGateway(gateways, vertx, serviceMap, "ws", isWebsocketEnabled(), getWebsocketPort(), pathLoadBalancer, serviceLoadBalancer);
if (gateways.isEmpty()) {
return null;
}
return new GatewayServiceTreeCache(curator, zkPath, serviceMap, gateways);
}
use of io.fabric8.gateway.ServiceMap in project fabric8 by jboss-fuse.
the class GatewayServiceTreeCacheTest method treeCacheEvent.
@Test
public void treeCacheEvent() throws Exception {
String zkPath = "/fabric/registry/clusters/test";
ServiceMap serviceMap = new ServiceMap();
CuratorFramework curator = mock(CuratorFramework.class);
GatewayServiceTreeCache cache = new GatewayServiceTreeCache(curator, zkPath, serviceMap);
String path = "/fabric/registry/clusters/test/default/0000001";
// Add container1 - master
// Add container2 - slave
cache.treeCacheEvent(event(path, CHILD_ADDED, data("test", "container1", "service1", "service2")));
cache.treeCacheEvent(event(path, CHILD_ADDED, data("test", "container2")));
assertEquals(1, serviceMap.getServices("default").size());
// Remove container1
// Update container2 - master
// Add container1 - slave
cache.treeCacheEvent(event(path, CHILD_REMOVED, data("test", "container1", "service1", "service2")));
cache.treeCacheEvent(event(path, CHILD_UPDATED, data("test", "container2", "service1", "service2")));
cache.treeCacheEvent(event(path, CHILD_ADDED, data("test", "container1")));
assertEquals(1, serviceMap.getServices("default").size());
// Remove container2
// Update container1 - master
// Add container2 - slave
cache.treeCacheEvent(event(path, CHILD_REMOVED, data("test", "container2", "service1", "service2")));
cache.treeCacheEvent(event(path, CHILD_UPDATED, data("test", "container1", "service1", "service2")));
cache.treeCacheEvent(event(path, CHILD_ADDED, data("test", "container2")));
assertEquals(1, serviceMap.getServices("default").size());
// Remove container2
// Add container2 - slave
cache.treeCacheEvent(event(path, CHILD_REMOVED, data("test", "container2")));
cache.treeCacheEvent(event(path, CHILD_ADDED, data("test", "container2")));
assertEquals(1, serviceMap.getServices("default").size());
}
use of io.fabric8.gateway.ServiceMap in project fabric8 by jboss-fuse.
the class DetectingGatewayTest method createGateway.
public DetectingGateway createGateway() {
String loadBalancerType = LoadBalancers.STICKY_LOAD_BALANCER;
int stickyLoadBalancerCacheSize = LoadBalancers.STICKY_LOAD_BALANCER_DEFAULT_CACHE_SIZE;
LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
ArrayList<Protocol> protocols = new ArrayList<Protocol>();
protocols.add(new StompProtocol());
protocols.add(new MqttProtocol());
protocols.add(new AmqpProtocol());
protocols.add(new OpenwireProtocol());
protocols.add(new HttpProtocol());
protocols.add(new SslProtocol());
DetectingGateway gateway = new DetectingGateway();
gateway.setPort(0);
gateway.setVertx(vertx);
SslConfig sslConfig = new SslConfig(new File(basedir(), "src/test/resources/server.ks"), "password");
sslConfig.setKeyPassword("password");
gateway.setSslConfig(sslConfig);
gateway.setServiceMap(serviceMap);
gateway.setProtocols(protocols);
gateway.setServiceLoadBalancer(serviceLoadBalancer);
gateway.setDefaultVirtualHost("broker1");
gateway.setConnectionTimeout(5000);
gateway.init();
gateways.add(gateway);
return gateway;
}
use of io.fabric8.gateway.ServiceMap in project fabric8 by jboss-fuse.
the class DetectingGatewayVirtualHostTest method createGateway.
public DetectingGateway createGateway() {
String loadBalancerType = LoadBalancers.ROUND_ROBIN_LOAD_BALANCER;
int stickyLoadBalancerCacheSize = LoadBalancers.STICKY_LOAD_BALANCER_DEFAULT_CACHE_SIZE;
LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
ArrayList<Protocol> protocols = new ArrayList<Protocol>();
protocols.add(new StompProtocol());
protocols.add(new MqttProtocol());
protocols.add(new AmqpProtocol());
protocols.add(new OpenwireProtocol());
protocols.add(new HttpProtocol());
protocols.add(new SslProtocol());
DetectingGateway gateway = new DetectingGateway();
gateway.setPort(0);
gateway.setVertx(vertx);
SslConfig sslConfig = new SslConfig(new File(basedir(), "src/test/resources/server.ks"), "password");
sslConfig.setKeyPassword("password");
gateway.setSslConfig(sslConfig);
gateway.setServiceMap(serviceMap);
gateway.setProtocols(protocols);
gateway.setServiceLoadBalancer(serviceLoadBalancer);
gateway.setDefaultVirtualHost("broker");
gateway.setConnectionTimeout(500000);
gateway.init();
gateways.add(gateway);
return gateway;
}
Aggregations