Example usage for io.netty.handler.codec.stomp DefaultStompFrame DefaultStompFrame

List of usage examples for io.netty.handler.codec.stomp DefaultStompFrame DefaultStompFrame

Introduction

In this page you can find the example usage for io.netty.handler.codec.stomp DefaultStompFrame DefaultStompFrame.

Prototype

public DefaultStompFrame(StompCommand command) 

Source Link

Usage

From source file:com.cmz.stomp.StompClientHandler.java

License:Apache License

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    state = ClientState.AUTHENTICATING;/*  www.j  a  v a 2s.  c o m*/
    StompFrame connFrame = new DefaultStompFrame(StompCommand.CONNECT);
    connFrame.headers().set(StompHeaders.ACCEPT_VERSION, "1.2");
    connFrame.headers().set(StompHeaders.HOST, StompClient.HOST);
    connFrame.headers().set(StompHeaders.LOGIN, StompClient.LOGIN);
    connFrame.headers().set(StompHeaders.PASSCODE, StompClient.PASSCODE);
    ctx.writeAndFlush(connFrame);
}

From source file:com.cmz.stomp.StompClientHandler.java

License:Apache License

@Override
protected void channelRead0(ChannelHandlerContext ctx, StompFrame frame) throws Exception {
    String subscrReceiptId = "001";
    String disconReceiptId = "002";
    switch (frame.command()) {
    case CONNECTED:
        StompFrame subscribeFrame = new DefaultStompFrame(StompCommand.SUBSCRIBE);
        subscribeFrame.headers().set(StompHeaders.DESTINATION, StompClient.TOPIC);
        subscribeFrame.headers().set(StompHeaders.RECEIPT, subscrReceiptId);
        subscribeFrame.headers().set(StompHeaders.ID, "1");
        System.out.println("connected, sending subscribe frame: " + subscribeFrame);
        state = ClientState.AUTHENTICATED;
        ctx.writeAndFlush(subscribeFrame);
        break;/* w  w  w.  ja v a 2 s.  c o  m*/
    case RECEIPT:
        String receiptHeader = frame.headers().getAsString(StompHeaders.RECEIPT_ID);
        if (state == ClientState.AUTHENTICATED && receiptHeader.equals(subscrReceiptId)) {
            StompFrame msgFrame = new DefaultStompFrame(StompCommand.SEND);
            msgFrame.headers().set(StompHeaders.DESTINATION, StompClient.TOPIC);
            msgFrame.content().writeBytes("some payload".getBytes());
            System.out.println("subscribed, sending message frame: " + msgFrame);
            state = ClientState.SUBSCRIBED;
            ctx.writeAndFlush(msgFrame);
        } else if (state == ClientState.DISCONNECTING && receiptHeader.equals(disconReceiptId)) {
            System.out.println("disconnected");
            ctx.close();
        } else {
            throw new IllegalStateException("received: " + frame + ", while internal state is " + state);
        }
        break;
    case MESSAGE:
        if (state == ClientState.SUBSCRIBED) {
            System.out.println("received frame: " + frame);
            StompFrame disconnFrame = new DefaultStompFrame(StompCommand.DISCONNECT);
            disconnFrame.headers().set(StompHeaders.RECEIPT, disconReceiptId);
            System.out.println("sending disconnect frame: " + disconnFrame);
            state = ClientState.DISCONNECTING;
            ctx.writeAndFlush(disconnFrame);
        }
        break;
    default:
        break;
    }
}

From source file:com.hop.hhxx.example.stomp.StompClientHandler.java

License:Apache License

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    state = ClientState.AUTHENTICATING;//from   ww w.ja  v  a2s . c  o m
    StompFrame connFrame = new DefaultStompFrame(StompCommand.CONNECT);
    connFrame.headers().set(StompHeaders.ACCEPT_VERSION, "1.2");
    connFrame.headers().set(StompHeaders.HOST, io.netty.example.stomp.StompClient.HOST);
    connFrame.headers().set(StompHeaders.LOGIN, io.netty.example.stomp.StompClient.LOGIN);
    connFrame.headers().set(StompHeaders.PASSCODE, io.netty.example.stomp.StompClient.PASSCODE);
    ctx.writeAndFlush(connFrame);
}

From source file:com.hop.hhxx.example.stomp.StompClientHandler.java

License:Apache License

@Override
protected void channelRead0(ChannelHandlerContext ctx, StompFrame frame) throws Exception {
    String subscrReceiptId = "001";
    String disconReceiptId = "002";
    switch (frame.command()) {
    case CONNECTED:
        StompFrame subscribeFrame = new DefaultStompFrame(StompCommand.SUBSCRIBE);
        subscribeFrame.headers().set(StompHeaders.DESTINATION, io.netty.example.stomp.StompClient.TOPIC);
        subscribeFrame.headers().set(StompHeaders.RECEIPT, subscrReceiptId);
        subscribeFrame.headers().set(StompHeaders.ID, "1");
        System.out.println("connected, sending subscribe frame: " + subscribeFrame);
        state = ClientState.AUTHENTICATED;
        ctx.writeAndFlush(subscribeFrame);
        break;/*from w w w .j  a va2 s  .c o  m*/
    case RECEIPT:
        String receiptHeader = frame.headers().getAsString(StompHeaders.RECEIPT_ID);
        if (state == ClientState.AUTHENTICATED && receiptHeader.equals(subscrReceiptId)) {
            StompFrame msgFrame = new DefaultStompFrame(StompCommand.SEND);
            msgFrame.headers().set(StompHeaders.DESTINATION, io.netty.example.stomp.StompClient.TOPIC);
            msgFrame.content().writeBytes("some payload".getBytes());
            System.out.println("subscribed, sending message frame: " + msgFrame);
            state = ClientState.SUBSCRIBED;
            ctx.writeAndFlush(msgFrame);
        } else if (state == ClientState.DISCONNECTING && receiptHeader.equals(disconReceiptId)) {
            System.out.println("disconnected");
            ctx.close();
        } else {
            throw new IllegalStateException("received: " + frame + ", while internal state is " + state);
        }
        break;
    case MESSAGE:
        if (state == ClientState.SUBSCRIBED) {
            System.out.println("received frame: " + frame);
            StompFrame disconnFrame = new DefaultStompFrame(StompCommand.DISCONNECT);
            disconnFrame.headers().set(StompHeaders.RECEIPT, disconReceiptId);
            System.out.println("sending disconnect frame: " + disconnFrame);
            state = ClientState.DISCONNECTING;
            ctx.writeAndFlush(disconnFrame);
        }
        break;
    default:
        break;
    }
}

From source file:io.aos.netty5.stomp.StompClientHandler.java

License:Apache License

@Override
protected void messageReceived(ChannelHandlerContext ctx, StompFrame frame) throws Exception {
    String subscrReceiptId = "001";
    String disconReceiptId = "002";
    switch (frame.command()) {
    case CONNECTED:
        StompFrame subscribeFrame = new DefaultStompFrame(StompCommand.SUBSCRIBE);
        subscribeFrame.headers().set(StompHeaders.DESTINATION, StompClient.TOPIC);
        subscribeFrame.headers().set(StompHeaders.RECEIPT, subscrReceiptId);
        subscribeFrame.headers().set(StompHeaders.ID, "1");
        System.out.println("connected, sending subscribe frame: " + subscribeFrame);
        state = ClientState.AUTHENTICATED;
        ctx.writeAndFlush(subscribeFrame);
        break;//  ww w.ja va 2s.co m
    case RECEIPT:
        String receiptHeader = frame.headers().get(StompHeaders.RECEIPT_ID);
        if (state == ClientState.AUTHENTICATED && receiptHeader.equals(subscrReceiptId)) {
            StompFrame msgFrame = new DefaultStompFrame(StompCommand.SEND);
            msgFrame.headers().set(StompHeaders.DESTINATION, StompClient.TOPIC);
            msgFrame.content().writeBytes("some payload".getBytes());
            System.out.println("subscribed, sending message frame: " + msgFrame);
            state = ClientState.SUBSCRIBED;
            ctx.writeAndFlush(msgFrame);
        } else if (state == ClientState.DISCONNECTING && receiptHeader.equals(disconReceiptId)) {
            System.out.println("disconnected");
            ctx.close();
        } else {
            throw new IllegalStateException("received: " + frame + ", while internal state is " + state);
        }
        break;
    case MESSAGE:
        if (state == ClientState.SUBSCRIBED) {
            System.out.println("received frame: " + frame);
            StompFrame disconnFrame = new DefaultStompFrame(StompCommand.DISCONNECT);
            disconnFrame.headers().set(StompHeaders.RECEIPT, disconReceiptId);
            System.out.println("sending disconnect frame: " + disconnFrame);
            state = ClientState.DISCONNECTING;
            ctx.writeAndFlush(disconnFrame);
        }
        break;
    default:
        break;
    }
}