Search in sources :

Example 11 with Message

use of com.generallycloud.baseio.container.jms.Message in project baseio by generallycloud.

the class ConsumerOnFuture method onResponse.

@Override
public void onResponse(SocketSession session, Future future) {
    ParamedProtobaseFuture f = (ParamedProtobaseFuture) future;
    try {
        Message message = messageDecoder.decode(f);
        onMessage.onReceive(message);
    } catch (MQException e) {
        DebugUtil.debug(e);
    }
}
Also used : MQException(com.generallycloud.baseio.container.jms.MQException) OnMessage(com.generallycloud.baseio.container.jms.client.OnMessage) Message(com.generallycloud.baseio.container.jms.Message) ParamedProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture)

Example 12 with Message

use of com.generallycloud.baseio.container.jms.Message in project baseio by generallycloud.

the class BrowserExecutable method exec.

@Override
public CmdResponse exec(CommandContext context, HashMap<String, String> params) {
    CmdResponse response = new CmdResponse();
    MessageBrowser browser = getMessageBrowser(context);
    if (browser == null) {
        response.setResponse("请先登录!");
        return response;
    }
    String messageId = params.get("-mid");
    if (StringUtil.isNullOrBlank(messageId)) {
        response.setResponse("参数不正确!\n" + "example:\n" + "browser -mid:mid");
        return response;
    }
    try {
        Message message = browser.browser(messageId);
        if (message == null) {
            response.setResponse("没有此id的消息!");
        } else {
            response.setResponse(message.toString());
        }
    } catch (Exception e) {
        logger.debug(e);
    }
    return response;
}
Also used : Message(com.generallycloud.baseio.container.jms.Message) CmdResponse(com.generallycloud.baseio.container.jms.cmd.CmdResponse) MessageBrowser(com.generallycloud.baseio.container.jms.client.MessageBrowser)

Example 13 with Message

use of com.generallycloud.baseio.container.jms.Message 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);
}
Also used : TextByteMessage(com.generallycloud.baseio.container.jms.TextByteMessage) Parameters(com.generallycloud.baseio.component.Parameters) ErrorMessage(com.generallycloud.baseio.container.jms.ErrorMessage) NullMessage(com.generallycloud.baseio.container.jms.NullMessage) TextByteMessage(com.generallycloud.baseio.container.jms.TextByteMessage) Message(com.generallycloud.baseio.container.jms.Message)

Example 14 with Message

use of com.generallycloud.baseio.container.jms.Message in project baseio by generallycloud.

the class TestTransaction method rollback.

static void rollback(MessageConsumer consumer) throws MQException {
    long old = System.currentTimeMillis();
    consumer.beginTransaction();
    consumer.receive(new OnMessage() {

        @Override
        public void onReceive(Message message) {
            System.out.println(message);
        }
    });
    consumer.rollback();
    System.out.println("Time:" + (System.currentTimeMillis() - old));
}
Also used : OnMessage(com.generallycloud.baseio.container.jms.client.OnMessage) Message(com.generallycloud.baseio.container.jms.Message) OnMessage(com.generallycloud.baseio.container.jms.client.OnMessage)

Example 15 with Message

use of com.generallycloud.baseio.container.jms.Message in project baseio by generallycloud.

the class TestSubscribe method test.

private static void test() throws Exception {
    LoggerFactory.configure();
    SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
    ServerConfiguration configuration = new ServerConfiguration(8300);
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    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);
    consumer.subscribe(new OnMessage() {

        @Override
        public void onReceive(Message message) {
            System.out.println(message);
        }
    });
    connector.close();
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) DefaultMessageConsumer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer) MessageConsumer(com.generallycloud.baseio.container.jms.client.MessageConsumer) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) OnMessage(com.generallycloud.baseio.container.jms.client.OnMessage) Message(com.generallycloud.baseio.container.jms.Message) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) FixedSession(com.generallycloud.baseio.container.FixedSession) DefaultMessageConsumer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer) OnMessage(com.generallycloud.baseio.container.jms.client.OnMessage) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)

Aggregations

Message (com.generallycloud.baseio.container.jms.Message)15 OnMessage (com.generallycloud.baseio.container.jms.client.OnMessage)8 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)6 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)6 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)6 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)6 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)6 FixedSession (com.generallycloud.baseio.container.FixedSession)6 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)6 MessageConsumer (com.generallycloud.baseio.container.jms.client.MessageConsumer)5 DefaultMessageConsumer (com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer)5 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)4 ParamedProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory)2 TextByteMessage (com.generallycloud.baseio.container.jms.TextByteMessage)2 MessageBrowser (com.generallycloud.baseio.container.jms.client.MessageBrowser)2 IOException (java.io.IOException)2 ParamedProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture)1 Parameters (com.generallycloud.baseio.component.Parameters)1 ErrorMessage (com.generallycloud.baseio.container.jms.ErrorMessage)1 MQException (com.generallycloud.baseio.container.jms.MQException)1