Package org.xbib.elasticsearch.websocket.client

Examples of org.xbib.elasticsearch.websocket.client.WebSocketClientRequest


        try {
            final String subscriberId = "oneclient";
            final String topic = "oneclienttest";
            final WebSocketClientFactory clientFactory = new NettyWebSocketClientFactory();
           
            final WebSocketClientRequest subscribe = clientFactory.newRequest()
                    .type("subscribe").data(jsonBuilder().startObject()
                    .field("subscriber", "singleclient")
                    .field("topic", topic).endObject());
           
            final WebSocketClientRequest publish = clientFactory.newRequest()
                    .type("publish").data(jsonBuilder().startObject()
                    .field("message", "Hello World")
                    .field("topic", topic).endObject());
           
            WebSocketClient client = clientFactory.newClient(getAddressOfNode("1"),
                    new WebSocketActionListener.Adapter() {
                        @Override
                        public void onConnect(WebSocketClient client) throws IOException {
                                logger.info("sending subscribe command, channel = {}", client.channel());
                                subscribe.send(client);
                                logger.info("sending publish command (to ourselves), channel = {}", client.channel());
                                publish.send(client);
                        }

                        @Override
                        public void onMessage(WebSocketClient client, WebSocketFrame frame) {
                            logger.info("frame received: " + frame);
View Full Code Here


        try {
            final String subscriberId = "twoclients";
            final String topic = "twoclienttest";
            final WebSocketClientFactory clientFactory = new NettyWebSocketClientFactory();

            final WebSocketClientRequest subscribe = clientFactory.newRequest()
                    .type("subscribe").data(jsonBuilder().startObject()
                    .field("subscriber", "doubleclient")
                    .field("topic", topic).endObject());
           
            final WebSocketClientRequest publish = clientFactory.newRequest()
                    .type("publish").data(jsonBuilder().startObject()
                    .field("message", "Hi there, I'm another client")
                    .field("topic", topic).endObject());
           
            // open first client
            WebSocketClient subscribingClient = clientFactory.newClient(getAddressOfNode("1"),
                    new WebSocketActionListener.Adapter() {
                        @Override
                        public void onConnect(WebSocketClient client) {
                            try {
                                logger.info("sending subscribe command, channel {}", client.channel());
                                subscribe.send(client);
                            } catch (Exception e) {
                            }
                        }

                        @Override
                        public void onMessage(WebSocketClient client, WebSocketFrame frame) {
                            logger.info("frame {} received for subscribing client {}", frame, client.channel());
                        }

                    });
           
            // open two client
            WebSocketClient publishingClient = clientFactory.newClient(getAddressOfNode("1"),
                    new WebSocketActionListener.Adapter() {
                        @Override
                        public void onConnect(WebSocketClient client) {
                            try {
                                logger.info("sending publish command, channel = {}", client.channel());
                                publish.send(client);
                            } catch (Exception e) {
                            }
                        }

                        @Override
View Full Code Here

TOP

Related Classes of org.xbib.elasticsearch.websocket.client.WebSocketClientRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.