Example usage for org.springframework.messaging.simp.stomp StompHeaderAccessor setSubscriptionId

List of usage examples for org.springframework.messaging.simp.stomp StompHeaderAccessor setSubscriptionId

Introduction

In this page you can find the example usage for org.springframework.messaging.simp.stomp StompHeaderAccessor setSubscriptionId.

Prototype

@Override
    public void setSubscriptionId(@Nullable String subscriptionId) 

Source Link

Usage

From source file:com.codeveo.lago.bot.stomp.client.WebSocketStompSession.java

public void subscribe(String destination, String receiptId) {
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSubscriptionId("sub-" + this.subscriptionIndex.getAndIncrement());
    headers.setDestination(destination);
    if (receiptId != null) {
        headers.setReceipt(receiptId);/*w  w  w.j a  va  2s.  c o m*/
    }
    sendInternal(MessageBuilder.withPayload(EMPTY_PAYLOAD).setHeaders(headers).build());
}

From source file:fr.jugorleans.poker.client.stomp.WebSocketStompSession.java

public void subscribe(String destination, String receiptId) {
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSubscriptionId("sub" + this.subscriptionIndex.getAndIncrement());
    headers.setDestination(destination);
    if (receiptId != null) {
        headers.setReceipt(receiptId);/*from   w w w.j av a 2s . com*/
    }
    sendInternal(MessageBuilder.withPayload(EMPTY_PAYLOAD).setHeaders(headers).build());
}

From source file:org.springframework.samples.portfolio.web.standalone.StandalonePortfolioControllerTests.java

@Test
public void getPositions() throws Exception {

    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSubscriptionId("0");
    headers.setDestination("/app/positions");
    headers.setSessionId("0");
    headers.setUser(new TestPrincipal("fabrice"));
    headers.setSessionAttributes(new HashMap<String, Object>());
    Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();

    this.annotationMethodMessageHandler.handleMessage(message);

    assertEquals(1, this.clientOutboundChannel.getMessages().size());
    Message<?> reply = this.clientOutboundChannel.getMessages().get(0);

    StompHeaderAccessor replyHeaders = StompHeaderAccessor.wrap(reply);
    assertEquals("0", replyHeaders.getSessionId());
    assertEquals("0", replyHeaders.getSubscriptionId());
    assertEquals("/app/positions", replyHeaders.getDestination());

    String json = new String((byte[]) reply.getPayload(), Charset.forName("UTF-8"));
    new JsonPathExpectationsHelper("$[0].company").assertValue(json, "Citrix Systems, Inc.");
    new JsonPathExpectationsHelper("$[1].company").assertValue(json, "Dell Inc.");
    new JsonPathExpectationsHelper("$[2].company").assertValue(json, "Microsoft");
    new JsonPathExpectationsHelper("$[3].company").assertValue(json, "Oracle");
}

From source file:smpp.networking.SimpleStompClient.java

public void subscribe(String destination, MessageHandler messageHandler) {

    String id = String.valueOf(this.subscriptionIndex.getAndIncrement());
    this.subscriptionHandlers.put(id, messageHandler);

    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSubscriptionId(id);
    headers.setDestination(destination);

    Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
    byte[] bytes = encoder.encode(message);
    try {/*from  w w w  . j a  v a  2 s .  c  o  m*/
        this.session.getRemote().sendString(new String(bytes, DEFAULT_CHARSET));
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.springframework.samples.portfolio.web.context.ContextPortfolioControllerTests.java

@Test
public void getPositions() throws Exception {

    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSubscriptionId("0");
    headers.setDestination("/app/positions");
    headers.setSessionId("0");
    headers.setUser(new TestPrincipal("fabrice"));
    headers.setSessionAttributes(new HashMap<String, Object>());
    Message<byte[]> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());

    this.clientOutboundChannelInterceptor.setIncludedDestinations("/app/positions");
    this.clientOutboundChannelInterceptor.startRecording();

    this.clientInboundChannel.send(message);

    Message<?> reply = this.clientOutboundChannelInterceptor.awaitMessage(5);
    assertNotNull(reply);/*from   w ww  .  ja v  a  2  s. c  om*/

    StompHeaderAccessor replyHeaders = StompHeaderAccessor.wrap(reply);
    assertEquals("0", replyHeaders.getSessionId());
    assertEquals("0", replyHeaders.getSubscriptionId());
    assertEquals("/app/positions", replyHeaders.getDestination());

    String json = new String((byte[]) reply.getPayload(), Charset.forName("UTF-8"));
    new JsonPathExpectationsHelper("$[0].company").assertValue(json, "Citrix Systems, Inc.");
    new JsonPathExpectationsHelper("$[1].company").assertValue(json, "Dell Inc.");
    new JsonPathExpectationsHelper("$[2].company").assertValue(json, "Microsoft");
    new JsonPathExpectationsHelper("$[3].company").assertValue(json, "Oracle");
}

From source file:org.springframework.messaging.simp.stomp.DefaultStompSession.java

private void unsubscribe(String id, @Nullable StompHeaders stompHeaders) {
    StompHeaderAccessor accessor = createHeaderAccessor(StompCommand.UNSUBSCRIBE);
    if (stompHeaders != null) {
        accessor.addNativeHeaders(stompHeaders);
    }/*from   w  w  w.  ja v  a2 s.com*/
    accessor.setSubscriptionId(id);
    Message<byte[]> message = createMessage(accessor, EMPTY_PAYLOAD);
    execute(message);
}

From source file:org.springframework.samples.portfolio.web.tomcat.TestStompClient.java

public void subscribe(String destination, MessageHandler messageHandler) {

    String id = String.valueOf(this.subscriptionIndex.getAndIncrement());
    this.subscriptionHandlers.put(id, messageHandler);

    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSubscriptionId(id);
    headers.setDestination(destination);

    Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
    byte[] bytes = encoder.encode(message);
    try {//from   w w  w. j  av a 2s .co  m
        this.session.sendMessage(new TextMessage(new String(bytes, DEFAULT_CHARSET)));
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}