public void attach(PhysicalConnectionSource source, ChannelTarget target, ChannelConnection connection) { if (source.isDirectConnection()) { // no event stream to attach since this is a direct connection return; } URI uri = target.getUri(); Channel channel = getChannel(uri, target.getChannelSide()); channel.attach(connection); connection.setCloseable(() -> { // no-op }); }
public void attach(PhysicalConnectionSource source, ChannelTarget target, ChannelConnection connection) { if (source.isDirectConnection()) { // no event stream to attach since this is a direct connection return; } URI uri = target.getUri(); Channel channel = getChannel(uri, target.getChannelSide()); channel.attach(connection); connection.setCloseable(() -> { // no-op }); }
public void attach(ChannelSource source, PhysicalConnectionTarget target, ChannelConnection connection) throws Fabric3Exception { connection.setCloseable(() -> { // no-op }); if (target.isDirectConnection()) { // no event stream to attach since this is a direct connection return; } URI uri = source.getUri(); Channel channel = getChannel(uri, source.getChannelSide()); URI targetUri = target.getUri(); channel.subscribe(targetUri, connection); }
public void attach(ChannelSource source, PhysicalConnectionTarget target, ChannelConnection connection) throws Fabric3Exception { connection.setCloseable(() -> { // no-op }); if (target.isDirectConnection()) { // no event stream to attach since this is a direct connection return; } URI uri = source.getUri(); Channel channel = getChannel(uri, source.getChannelSide()); URI targetUri = target.getUri(); channel.subscribe(targetUri, connection); }
@SuppressWarnings("unchecked") public void attach(PhysicalConnectionSource source, NATSConnectionTarget target, ChannelConnection connection) { Nats nats = connectionManager.getNats(target); if (!source.isDirectConnection()) { String topic = target.getTopic() != null ? target.getTopic() : target.getDefaultTopic(); String serializerName = target.getData().getSerializer(); Function<Object, String> serializer = serializerName != null ? InstanceResolver.getInstance(serializerName, info, cm) : null; connection.getEventStream().addHandler((event, batch) -> { String serialized = serializer != null ? serializer.apply(event) : event.toString(); nats.publish(topic, serialized); }); connection.setCloseable(() -> connectionManager.release(target.getChannelUri(), topic)); } }
@SuppressWarnings("unchecked") public void subscribe(NATSConnectionSource source, ChannelConnection connection) { URI channelUri = source.getChannelUri(); String topic = source.getTopic() != null ? source.getTopic() : source.getDefaultTopic(); Holder holder = connections.get(channelUri); boolean exists = holder != null; // only create the subscription Nats nats; if (!exists) { holder = createNats(source); } else { holder.counter++; } nats = holder.delegate; connections.put(channelUri, holder); FanoutHandler messageHandler = new FanoutHandler(source.getConsumerId(), connection); Subscription subscription = nats.subscribe(topic, messageHandler); // set the closeable callback connection.setCloseable(() -> { subscription.close(); release(channelUri, topic); }); }
public void attach(NATSConnectionSource source, PhysicalConnectionTarget target, ChannelConnection connection) { String topic = source.getTopic() != null ? source.getTopic() : source.getDefaultTopic(); connection.setCloseable(() -> connectionManager.release(source.getChannelUri(), topic)); if (target.isDirectConnection()) { Class<?> type = target.getServiceInterface(); connectionManager.createDirectConsumer(type, source); // create consumer, which will be returned by the direct connection factory } else { String deserializerName = source.getData().getDeserializer(); Function deserializer = deserializerName != null ? InstanceResolver.getInstance(deserializerName, info, cm) : null; connection.getEventStream().addHandler(0, new EventStreamHandler() { private EventStreamHandler next; @SuppressWarnings("unchecked") public void handle(Object message, boolean batch) { Object body = deserializer != null ? deserializer.apply(message) : message; next.handle(body, batch); } public void setNext(EventStreamHandler next) { this.next = next; } public EventStreamHandler getNext() { return next; } }); connectionManager.subscribe(source, connection); } }