Esempio n. 1
0
  public static void main(String[] args) {
    try {
      DefaultWampChannelFactory factory = new DefaultWampChannelFactory();

      WampChannel channel = factory.createJsonChannel(new URI("ws://127.0.0.1:8080/ws"), "realm1");

      CompletionStage open = channel.open();

      open.toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);

      WampRealmServiceProvider services = channel.getRealmProxy().getServices();

      Subject<Integer, Integer> subject = services.getSubject(Integer.class, "com.myapp.topic1");

      Subscription disposable =
          subject.subscribe(
              new Action1<Integer>() {
                @Override
                public void call(Integer counter) {
                  System.out.println("Got " + counter);
                }
              });

      System.in.read();

      disposable.unsubscribe();

      System.in.read();

    } catch (Exception ex) {
      // Catch everything! :(
      System.out.println(ex);
    }
  }
 @Test
 public void testUDPconnection() throws Exception {
   Subject<byte[], byte[]> sub = PublishSubject.create();
   SimpleChan simpleadapter = new SimpleChan(sub);
   TestAwaitableObserver<byte[]> monitor = new TestAwaitableObserver<>();
   sub.subscribe(monitor);
   int port = rand.nextInt(100) + 8000;
   ServerFrontEnd udpSrv = ServerFrontEnd.udp(simpleadapter, port);
   udpSrv.startAsync().awaitRunning();
   sendMSG(MSG.getBytes(), port);
   monitor.awaitOnNext(1, TIMEOUT);
   assertThat("msg was received", monitor.getOnNextEvents().get(0), equalTo(MSG.getBytes()));
 }
 @Test
 public void testUDPLargePacket() throws Exception {
   Subject<byte[], byte[]> sub = PublishSubject.create();
   SimpleChan simpleadapter = new SimpleChan(sub);
   TestAwaitableObserver<byte[]> monitor = new TestAwaitableObserver<>();
   sub.subscribe(monitor);
   int port = rand.nextInt(100) + 8000;
   ServerFrontEnd udpSrv = ServerFrontEnd.udp(simpleadapter, port, 65536);
   byte[] msg = new byte[65535 - 28]; // max payload size
   rand.nextBytes(msg);
   udpSrv.startAsync().awaitRunning();
   sendMSG(msg, port);
   monitor.awaitOnNext(1, TIMEOUT);
   assertThat("msg was received", monitor.getOnNextEvents().get(0), equalTo(msg));
 }
Esempio n. 4
0
 @Override
 public Subscription subscribe(Observer<? super V> observer) {
   return publish.subscribe(observer);
 }