Search in sources :

Example 1 with PutMessage

use of pers.cy.iris.commons.network.protocol.request.PutMessage in project iris by chicc999.

the class NettyClientTest method init.

private void init() {
    nettyClient = new NettyClient(new NettyClientConfig());
    try {
        nettyClient.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        Channel channel = nettyClient.createChannelSync(new InetSocketAddress("localhost", 50088));
        PutMessage command = new PutMessage();
        command.setProducerId(new ProducerId(new ConnectionId(new ClientId("1.0", "localhost", System.currentTimeMillis()))));
        Message message = new Message("test", "第一条消息", "1");
        message.setApp("app");
        Message[] messages = new Message[1];
        messages[0] = message;
        command.setMessages(messages);
        Command command1 = nettyClient.sync(channel, command, 10000);
        if (command1.getHeader().getStatus() != 200) {
            System.out.println(command1.getHeader().getError());
        }
    } catch (ConnectException e) {
        e.printStackTrace();
    } catch (RequestTimeoutException e) {
        e.printStackTrace();
    } catch (RemotingIOException e) {
        e.printStackTrace();
    }
}
Also used : Message(pers.cy.iris.commons.model.message.Message) PutMessage(pers.cy.iris.commons.network.protocol.request.PutMessage) ProducerId(pers.cy.iris.commons.network.netty.session.ProducerId) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) RemotingIOException(pers.cy.iris.commons.exception.RemotingIOException) RequestTimeoutException(pers.cy.iris.commons.exception.RequestTimeoutException) ConnectException(pers.cy.iris.commons.exception.ConnectException) RemotingIOException(pers.cy.iris.commons.exception.RemotingIOException) NettyClient(pers.cy.iris.commons.network.netty.client.NettyClient) RequestTimeoutException(pers.cy.iris.commons.exception.RequestTimeoutException) ConnectionId(pers.cy.iris.commons.network.netty.session.ConnectionId) Command(pers.cy.iris.commons.network.protocol.Command) NettyClientConfig(pers.cy.iris.commons.network.netty.client.NettyClientConfig) ClientId(pers.cy.iris.commons.network.netty.session.ClientId) PutMessage(pers.cy.iris.commons.network.protocol.request.PutMessage) ConnectException(pers.cy.iris.commons.exception.ConnectException)

Example 2 with PutMessage

use of pers.cy.iris.commons.network.protocol.request.PutMessage in project iris by chicc999.

the class PutMessageHandler method process.

@Override
public Command process(ChannelHandlerContext ctx, Command command) throws Exception {
    PutMessage putMessage = (PutMessage) command;
    System.out.println("收到putMessage请求," + new String(putMessage.getMessages()[0].getBody()));
    Message[] messages = putMessage.getMessages();
    for (Message message : messages) {
        store.putMessage((StoreMessage) message);
    }
    return new ErrorResponse(200, "", command.getRequestId());
}
Also used : Message(pers.cy.iris.commons.model.message.Message) PutMessage(pers.cy.iris.commons.network.protocol.request.PutMessage) StoreMessage(pers.cy.iris.commons.model.message.StoreMessage) PutMessage(pers.cy.iris.commons.network.protocol.request.PutMessage) ErrorResponse(pers.cy.iris.commons.network.protocol.response.ErrorResponse)

Aggregations

Message (pers.cy.iris.commons.model.message.Message)2 PutMessage (pers.cy.iris.commons.network.protocol.request.PutMessage)2 Channel (io.netty.channel.Channel)1 InetSocketAddress (java.net.InetSocketAddress)1 ConnectException (pers.cy.iris.commons.exception.ConnectException)1 RemotingIOException (pers.cy.iris.commons.exception.RemotingIOException)1 RequestTimeoutException (pers.cy.iris.commons.exception.RequestTimeoutException)1 StoreMessage (pers.cy.iris.commons.model.message.StoreMessage)1 NettyClient (pers.cy.iris.commons.network.netty.client.NettyClient)1 NettyClientConfig (pers.cy.iris.commons.network.netty.client.NettyClientConfig)1 ClientId (pers.cy.iris.commons.network.netty.session.ClientId)1 ConnectionId (pers.cy.iris.commons.network.netty.session.ConnectionId)1 ProducerId (pers.cy.iris.commons.network.netty.session.ProducerId)1 Command (pers.cy.iris.commons.network.protocol.Command)1 ErrorResponse (pers.cy.iris.commons.network.protocol.response.ErrorResponse)1