/** * <p>Publishes the given {@code data} onto this channel.</p> * <p>The {@code data} published must not be null and can be any object that * can be natively converted to JSON (numbers, strings, arrays, lists, maps), * or objects for which a JSON converter has been registered with the * infrastructure responsible of the JSON conversion.</p> * * @param data the data to publish * @see #publish(Object, ClientSession.MessageListener) */ public default void publish(Object data) { publish(data, ClientSession.MessageListener.NOOP); }
/** * @param message the message to publish * @param callback the message callback to notify of the publish result * @deprecated use {@link #publish(Message.Mutable, ClientSession.MessageListener)} instead */ @Deprecated public default void publish(Message.Mutable message, MessageListener callback) { publish(message, m -> callback.onMessage(this, m)); }
/** * @param data the data to publish * @param callback the message callback to notify of the publish result * @deprecated use {@link #publish(Object, ClientSession.MessageListener)} instead */ @Deprecated public default void publish(Object data, MessageListener callback) { publish(data, message -> callback.onMessage(this, message)); }
public void testPubSub() { String pubSubUrl = "http://" + cometdHost + ":" + cometdListenPort + "/cometd"; String fraudAlertChannel = "/fraudAlert"; HttpClient httpClient = new HttpClient(); try { httpClient.start(); } catch (Exception e) { e.printStackTrace(); } // Prepare the transport Map<String, Object> options = new HashMap<String, Object>(); ClientTransport transport = new LongPollingTransport(options, httpClient); // Create the BayeuxClient BayeuxClient bayuexClient = new BayeuxClient(pubSubUrl, transport); bayuexClient.handshake(); boolean handshaken = bayuexClient.waitFor(5000, BayeuxClient.State.CONNECTED); if (handshaken) { System.out.println("Connected to Cometd Http PubSub Platform"); } else{ System.out.println("Could not connect to Cometd Http PubSub Platform"); } bayuexClient.getChannel(fraudAlertChannel).publish("TEST"); }