use of pers.cy.iris.commons.model.message.Message 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();
}
}
use of pers.cy.iris.commons.model.message.Message in project iris by chicc999.
the class PutMessage method encodeBody.
@Override
protected ByteBuf encodeBody(ByteBuf body) {
Serializer.writeByteString(producerId.getProducerId(), body);
body.writeInt(messages.length);
for (Message message : messages) {
message.encode(body);
}
body.writeShort(this.queueId);
return body;
}
use of pers.cy.iris.commons.model.message.Message in project iris by chicc999.
the class PutMessage method decodeBody.
@Override
protected void decodeBody(ByteBuf in) throws Exception {
producerId = new ProducerId(Serializer.readByteString(in));
//读取消息条数
int count = in.readInt();
// 需要解码为BrokerMessage类型
messages = new Message[count];
for (int i = 0; i < count; i++) {
Message message = new Message();
messages[i] = message.decode(in);
}
// 队列ID
queueId = in.readShort();
}
use of pers.cy.iris.commons.model.message.Message 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());
}
Aggregations