use of com.generallycloud.baseio.container.jms.TextByteMessage in project baseio by generallycloud.
the class TestListenerByteMessage method main.
public static void main(String[] args) throws Exception {
SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(8300));
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandle);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
FixedSession session = new FixedSession(connector.connect());
session.login("admin", "admin100");
MessageConsumer consumer = new DefaultMessageConsumer(session);
final long old = System.currentTimeMillis();
consumer.receive(new OnMessage() {
@Override
public void onReceive(Message message) {
System.out.println(message);
if (message.getMsgType() == Message.TYPE_TEXT_BYTE) {
TextByteMessage _Message = (TextByteMessage) message;
System.out.println(new String(_Message.getByteArray(), Encoding.UTF8));
}
System.out.println("Time:" + (System.currentTimeMillis() - old));
}
});
ThreadUtil.sleep(30000000);
connector.close();
}
use of com.generallycloud.baseio.container.jms.TextByteMessage in project baseio by generallycloud.
the class TestTellerByteMessage method main.
public static void main(String[] args) throws Exception {
SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(8300));
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandle);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
FixedSession session = new FixedSession(connector.connect());
session.login("admin", "admin100");
MessageProducer producer = new DefaultMessageProducer(session);
TextByteMessage message = new TextByteMessage("msgId", "uuid", "============", "你好!".getBytes(session.getContext().getEncoding()));
long old = System.currentTimeMillis();
for (int i = 0; i < 5; i++) {
producer.offer(message);
}
System.out.println("Time:" + (System.currentTimeMillis() - old));
connector.close();
}
use of com.generallycloud.baseio.container.jms.TextByteMessage in project baseio by generallycloud.
the class FixedMessageConsumer method onReceive.
@Override
public void onReceive(Message message) {
int msgType = message.getMsgType();
if (Message.TYPE_MAP == msgType) {
MapMessage m = (MapMessage) message;
String eventName = m.getParameter("eventName");
OnMappedMessage onMessage = onMappedMessages.get(eventName);
if (onMessage == null) {
return;
}
onMessage.onReceive(m);
} else if (Message.TYPE_MAP_BYTE == msgType) {
MapByteMessage m = (MapByteMessage) message;
String eventName = m.getParameter("eventName");
OnMappedMessage onMessage = onMappedMessages.get(eventName);
if (onMessage == null) {
return;
}
onMessage.onReceive(m);
} else if (Message.TYPE_TEXT == msgType) {
if (onTextMessage != null) {
onTextMessage.onReceive((TextMessage) message);
}
} else if (Message.TYPE_TEXT_BYTE == msgType) {
if (onTextByteMessage != null) {
onTextByteMessage.onReceive((TextByteMessage) message);
}
} else if (Message.TYPE_ERROR == msgType) {
if (onErrorMessage != null) {
onErrorMessage.onReceive((ErrorMessage) message);
}
} else if (Message.TYPE_NULL == msgType) {
if (onNullMessage != null) {
onNullMessage.onReceive((NullMessage) message);
}
}
}
use of com.generallycloud.baseio.container.jms.TextByteMessage in project baseio by generallycloud.
the class TextByteMessageDecoder method decode.
@Override
public Message decode(ParamedProtobaseFuture future) {
Parameters param = future.getParameters();
String messageId = param.getParameter("msgId");
String queueName = param.getParameter("queueName");
String text = param.getParameter("text");
byte[] array = future.getReadBinary();
return new TextByteMessage(messageId, queueName, text, array);
}
use of com.generallycloud.baseio.container.jms.TextByteMessage in project baseio by generallycloud.
the class MQBrowserServlet method doAccept.
@Override
public void doAccept(SocketSession session, ParamedProtobaseFuture future, MQSessionAttachment attachment) throws Exception {
Parameters param = future.getParameters();
String messageId = param.getParameter("messageId");
Message message = NullMessage.NULL_MESSAGE;
MQContext context = getMQContext();
String cmd = param.getParameter("cmd");
if (StringUtil.isNullOrBlank(cmd)) {
message = ErrorMessage.CMD_NOT_FOUND_MESSAGE;
} else {
if (SIZE.equals(cmd)) {
future.write(String.valueOf(context.messageSize()));
} else if (BROWSER.equals(cmd)) {
if (!StringUtil.isNullOrBlank(messageId)) {
message = context.browser(messageId);
if (message == null) {
message = NullMessage.NULL_MESSAGE;
future.write(message.toString());
} else {
int msgType = message.getMsgType();
String content = message.toString();
future.write(content);
if (msgType == 3) {
TextByteMessage byteMessage = (TextByteMessage) message;
byte[] bytes = byteMessage.getByteArray();
future.writeBinary(bytes);
}
}
}
} else if (ONLINE.equals(cmd)) {
boolean bool = context.isOnLine(param.getParameter("queueName"));
future.write(String.valueOf(bool));
}
}
session.flush(future);
}
Aggregations