@Autowired public ProxyResponseHandler(Gson gson, String requestTopic, String replyToTopic, WebSocketKafkaProxyConfig proxyConfig, RequestResponseMatcher requestResponseMatcher) { this.gson = gson; this.requestTopic = requestTopic; this.replyToTopic = replyToTopic; this.requestResponseMatcher = requestResponseMatcher; WebSocketKafkaProxyClient webSocketKafkaProxyClient = new WebSocketKafkaProxyClient((message, client) -> {}); webSocketKafkaProxyClient.setWebSocketKafkaProxyConfig(proxyConfig); this.proxyClient = webSocketKafkaProxyClient; }
public FrontendProxyClient(String requestTopic, String replyToTopic, WebSocketKafkaProxyConfig proxyConfig, NotificationHandler notificationHandler, RequestResponseMatcher requestResponseMatcher, Gson gson, RingBuffer<ServerEvent> ringBuffer) { this.requestTopic = requestTopic; this.replyToTopic = replyToTopic; this.proxyConfig = proxyConfig; this.notificationHandler = notificationHandler; this.requestResponseMatcher = requestResponseMatcher; this.gson = gson; this.ringBuffer = ringBuffer; this.client = new WebSocketKafkaProxyClient((message, client) -> {}); client.setWebSocketKafkaProxyConfig(proxyConfig); }
@Autowired public ProxyServerEventHandler(Gson gson, WebSocketKafkaProxyConfig proxyConfig, HandlersMapper requestHandlersMapper) { this.gson = gson; this.requestHandlersMapper = requestHandlersMapper; WebSocketKafkaProxyClient webSocketKafkaProxyClient = new WebSocketKafkaProxyClient((message, client) -> {}); webSocketKafkaProxyClient.setWebSocketKafkaProxyConfig(proxyConfig); this.proxyClient = webSocketKafkaProxyClient; this.proxyClient.start(); }
@Autowired public ProxyMessageDispatcher(Gson gson, WebSocketKafkaProxyConfig proxyConfig) { this.gson = gson; WebSocketKafkaProxyClient webSocketKafkaProxyClient = new WebSocketKafkaProxyClient((message, client) -> {}); webSocketKafkaProxyClient.setWebSocketKafkaProxyConfig(proxyConfig); this.proxyClient = webSocketKafkaProxyClient; this.proxyClient.start(); }
@Bean public AuthProxyClient rpcClient(NotificationHandler notificationHandler, WebSocketKafkaProxyConfig proxyConfig, RequestResponseMatcher requestResponseMatcher, Gson gson) { WebSocketKafkaProxyClient proxyClient = new WebSocketKafkaProxyClient(notificationHandler); proxyClient.setWebSocketKafkaProxyConfig(proxyConfig); AuthProxyClient client = new AuthProxyClient(REQUEST_TOPIC, RESPONSE_TOPIC, proxyClient, requestResponseMatcher, gson); client.start(); return client; } }
@Bean public PluginProxyClient rpcClient(NotificationHandler notificationHandler, WebSocketKafkaProxyConfig proxyConfig, RequestResponseMatcher requestResponseMatcher, Gson gson) { WebSocketKafkaProxyClient proxyClient = new WebSocketKafkaProxyClient(notificationHandler); proxyClient.setWebSocketKafkaProxyConfig(proxyConfig); PluginProxyClient client = new PluginProxyClient(REQUEST_TOPIC, RESPONSE_TOPIC, proxyClient, requestResponseMatcher, gson); client.start(); return client; } }
public static void main(String[] args) { ProxyClient client = new WebSocketKafkaProxyClient((message, proxyClient) -> System.out.println("Received message: " + message)); client.start(); CompletableFuture<ProxyMessage> healthFuture = client.push(ProxyMessageBuilder.health()); System.out.println("Topic health: " + healthFuture.join()); CompletableFuture<ProxyMessage> subscribeFuture = client.push(ProxyMessageBuilder.subscribe(new SubscribePayload("kafka-ws-topic"))); System.out.println("Topic subscribe: " + subscribeFuture.join()); try { Thread.sleep(20000); } catch (InterruptedException e) { e.printStackTrace(); } finally { client.shutdown(); } } }
@Override public void start() { client.start(); client.push(ProxyMessageBuilder.create(new TopicsPayload(Arrays.asList(requestTopic, replyToTopic)))).join(); UUID uuid = UUID.randomUUID(); Executor executionPool = Executors.newFixedThreadPool(proxyConfig.getWorkerThreads()); for (int i = 0; i < proxyConfig.getWorkerThreads(); i++) { executionPool.execute(() -> { WebSocketKafkaProxyClient client = new WebSocketKafkaProxyClient(notificationHandler); client.setWebSocketKafkaProxyConfig(proxyConfig); client.start(); client.push(ProxyMessageBuilder.subscribe(new SubscribePayload(replyToTopic, uuid.toString()))).join(); }); } pingServer(); }
@Bean public Executor executionPool(NotificationHandler notificationHandler, WebSocketKafkaProxyConfig proxyConfig) { Executor executionPool = Executors.newFixedThreadPool(proxyConfig.getWorkerThreads()); for (int i = 0; i < proxyConfig.getWorkerThreads(); i++) { executionPool.execute(() -> { WebSocketKafkaProxyClient client = new WebSocketKafkaProxyClient(notificationHandler); client.setWebSocketKafkaProxyConfig(proxyConfig); client.start(); client.push(ProxyMessageBuilder.create(new TopicsPayload(REQUEST_TOPIC))).join(); client.push(ProxyMessageBuilder.subscribe(new SubscribePayload(REQUEST_TOPIC, proxyConfig.getConsumerGroup()))).join(); }); } return executionPool; }
public DistributedProxyFilterRegistry(Gson gson, WebSocketKafkaProxyConfig proxyConfig) { this.gson = gson; this.proxyClient = new WebSocketKafkaProxyClient((message, proxyClient) -> handleSubscriptionMessage(message, gson)); proxyClient.setWebSocketKafkaProxyConfig(proxyConfig); proxyClient.start(); proxyClient.push(ProxyMessageBuilder.subscribe(new SubscribePayload(SUBSCRIPTION_TOPIC, "fr-" + UUID.randomUUID()))).thenAccept(message -> { if (message.getStatus() == null || message.getStatus() != 0) { MessagePayload payload = (MessagePayload) message.getPayload(); throw new HiveException("Response message is failed: " + payload.getMessage()); } }); }