Search in sources :

Example 1 with BytedMessage

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

the class DefaultMessageProducer method offer.

private boolean offer(Message message, String serviceName) throws MQException {
    String param = message.toString();
    ProtobaseFuture future = null;
    int msgType = message.getMsgType();
    try {
        if (msgType == Message.TYPE_TEXT || msgType == Message.TYPE_MAP) {
            future = session.request(serviceName, param);
        } else if (msgType == Message.TYPE_TEXT_BYTE || msgType == Message.TYPE_MAP_BYTE) {
            BytedMessage _message = (BytedMessage) message;
            future = session.request(serviceName, param, _message.getByteArray());
        } else {
            throw new MQException("msgType:" + msgType);
        }
    } catch (IOException e) {
        throw new MQException(e.getMessage(), e);
    }
    String result = future.getReadText();
    if (result.length() == 1) {
        return "T".equals(result);
    }
    throw new MQException(result);
}
Also used : ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) MQException(com.generallycloud.baseio.container.jms.MQException) IOException(java.io.IOException) BytedMessage(com.generallycloud.baseio.container.jms.BytedMessage)

Example 2 with BytedMessage

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

the class Consumer method push.

// FIXME push 失败时对message进行回收,并移除Consumer
public void push(Message message) throws IOException {
    this.message = message;
    TransactionSection section = attachment.getTransactionSection();
    if (section != null) {
        section.offerMessage(message);
    }
    int msgType = message.getMsgType();
    String content = message.toString();
    SocketSession session = this.session;
    ProtobaseFuture f = new ProtobaseFutureImpl(session.getContext(), future.getFutureId(), future.getFutureName());
    f.write(content);
    if (msgType == Message.TYPE_TEXT || msgType == Message.TYPE_MAP) {
        session.flush(f);
    } else if (msgType == Message.TYPE_TEXT_BYTE || msgType == Message.TYPE_MAP_BYTE) {
        BytedMessage byteMessage = (BytedMessage) message;
        byte[] bytes = byteMessage.getByteArray();
        f.writeBinary(bytes);
        session.flush(f);
    }
}
Also used : ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) BytedMessage(com.generallycloud.baseio.container.jms.BytedMessage)

Aggregations

ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)2 BytedMessage (com.generallycloud.baseio.container.jms.BytedMessage)2 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)1 SocketSession (com.generallycloud.baseio.component.SocketSession)1 MQException (com.generallycloud.baseio.container.jms.MQException)1 IOException (java.io.IOException)1