当前位置: 首页>>代码示例>>Java>>正文


Java RemotingCommand类代码示例

本文整理汇总了Java中org.apache.rocketmq.remoting.protocol.RemotingCommand的典型用法代码示例。如果您正苦于以下问题:Java RemotingCommand类的具体用法?Java RemotingCommand怎么用?Java RemotingCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RemotingCommand类属于org.apache.rocketmq.remoting.protocol包,在下文中一共展示了RemotingCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resetOffset

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
public RemotingCommand resetOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final ResetOffsetRequestHeader requestHeader =
        (ResetOffsetRequestHeader) request.decodeCommandCustomHeader(ResetOffsetRequestHeader.class);
    log.info("[reset-offset] reset offset started by {}. topic={}, group={}, timestamp={}, isForce={}",
        RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup(),
        requestHeader.getTimestamp(), requestHeader.isForce());
    boolean isC = false;
    LanguageCode language = request.getLanguage();
    switch (language) {
        case CPP:
            isC = true;
            break;
    }
    return this.brokerController.getBroker2Client().resetOffset(requestHeader.getTopic(), requestHeader.getGroup(),
        requestHeader.getTimestamp(), requestHeader.isForce(), isC);
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:17,代码来源:AdminBrokerProcessor.java

示例2: encode

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
@Override
public void encode(ChannelHandlerContext ctx, RemotingCommand remotingCommand, ByteBuf out)
    throws Exception {
    try {
        ByteBuffer header = remotingCommand.encodeHeader();
        out.writeBytes(header);
        byte[] body = remotingCommand.getBody();
        if (body != null) {
            out.writeBytes(body);
        }
    } catch (Exception e) {
        log.error("encode exception, " + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), e);
        if (remotingCommand != null) {
            log.error(remotingCommand.toString());
        }
        RemotingUtil.closeChannel(ctx.channel());
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:19,代码来源:NettyEncoder.java

示例3: invokeAsync

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
@Override
public void invokeAsync(String addr, RemotingCommand request, long timeoutMillis, InvokeCallback invokeCallback)
    throws InterruptedException, RemotingConnectException, RemotingTooMuchRequestException, RemotingTimeoutException,
    RemotingSendRequestException {
    final Channel channel = this.getAndCreateChannel(addr);
    if (channel != null && channel.isActive()) {
        try {
            if (this.rpcHook != null) {
                this.rpcHook.doBeforeRequest(addr, request);
            }
            this.invokeAsyncImpl(channel, request, timeoutMillis, invokeCallback);
        } catch (RemotingSendRequestException e) {
            log.warn("invokeAsync: send request exception, so close the channel[{}]", addr);
            this.closeChannel(addr, channel);
            throw e;
        }
    } else {
        this.closeChannel(addr, channel);
        throw new RemotingConnectException(addr);
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:22,代码来源:NettyRemotingClient.java

示例4: invokeOneway

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
@Override
public void invokeOneway(String addr, RemotingCommand request, long timeoutMillis) throws InterruptedException,
    RemotingConnectException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException {
    final Channel channel = this.getAndCreateChannel(addr);
    if (channel != null && channel.isActive()) {
        try {
            if (this.rpcHook != null) {
                this.rpcHook.doBeforeRequest(addr, request);
            }
            this.invokeOnewayImpl(channel, request, timeoutMillis);
        } catch (RemotingSendRequestException e) {
            log.warn("invokeOneway: send request exception, so close the channel[{}]", addr);
            this.closeChannel(addr, channel);
            throw e;
        }
    } else {
        this.closeChannel(addr, channel);
        throw new RemotingConnectException(addr);
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:21,代码来源:NettyRemotingClient.java

示例5: msgContentCheck

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
protected RemotingCommand msgContentCheck(final ChannelHandlerContext ctx,
    final SendMessageRequestHeader requestHeader, RemotingCommand request,
    final RemotingCommand response) {
    //首先topic的长度不能 > 127个字符串
    if (requestHeader.getTopic().length() > Byte.MAX_VALUE) {
        log.warn("putMessage message topic length too long {}", requestHeader.getTopic().length());
        response.setCode(ResponseCode.MESSAGE_ILLEGAL);
        return response;
    }

    //消息的的扩展字段不能超过32767 个字节
    if (requestHeader.getProperties() != null && requestHeader.getProperties().length() > Short.MAX_VALUE) {
        log.warn("putMessage message properties length too long {}", requestHeader.getProperties().length());
        response.setCode(ResponseCode.MESSAGE_ILLEGAL);
        return response;
    }
    //消息体不能超过64k
    if (request.getBody().length > DBMsgConstants.MAX_BODY_SIZE) {
        log.warn(" topic {}  msg body size {}  from {}", requestHeader.getTopic(),
            request.getBody().length, ChannelUtil.getRemoteIp(ctx.channel()));
        response.setRemark("msg body must be less 64KB");
        response.setCode(ResponseCode.MESSAGE_ILLEGAL);
        return response;
    }
    return response;
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:27,代码来源:AbstractSendMessageProcessor.java

示例6: lockBatchMQ

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
public Set<MessageQueue> lockBatchMQ(//
    final String addr, //
    final LockBatchRequestBody requestBody, //
    final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.LOCK_BATCH_MQ, null);

    request.setBody(requestBody.encode());
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
        request, timeoutMillis);
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            LockBatchResponseBody responseBody = LockBatchResponseBody.decode(response.getBody(), LockBatchResponseBody.class);
            Set<MessageQueue> messageQueues = responseBody.getLockOKMQSet();
            return messageQueues;
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:22,代码来源:MQClientAPIImpl.java

示例7: testSendMessageSync_Success

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
@Test
public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException {
    doAnswer(new Answer() {
        @Override public Object answer(InvocationOnMock mock) throws Throwable {
            RemotingCommand request = mock.getArgument(1);
            return createSuccessResponse(request);
        }
    }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong());

    SendMessageRequestHeader requestHeader = createSendMessageRequestHeader();

    SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader,
        3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl);

    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
    assertThat(sendResult.getOffsetMsgId()).isEqualTo("123");
    assertThat(sendResult.getQueueOffset()).isEqualTo(123L);
    assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1);
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:20,代码来源:MQClientAPIImplTest.java

示例8: getProducerConnectionList

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
public ProducerConnection getProducerConnectionList(final String addr, final String producerGroup, final long timeoutMillis)
    throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException,
    MQBrokerException {
    GetProducerConnectionListRequestHeader requestHeader = new GetProducerConnectionListRequestHeader();
    requestHeader.setProducerGroup(producerGroup);

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_PRODUCER_CONNECTION_LIST, requestHeader);

    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
        request, timeoutMillis);
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return ProducerConnection.decode(response.getBody(), ProducerConnection.class);
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:21,代码来源:MQClientAPIImpl.java

示例9: processResponseCommand

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
/**
 * Process response from remote peer to the previous issued requests.
 * @param ctx channel handler context.
 * @param cmd response command instance.
 */
public void processResponseCommand(ChannelHandlerContext ctx, RemotingCommand cmd) {
    final int opaque = cmd.getOpaque();
    final ResponseFuture responseFuture = responseTable.get(opaque);
    if (responseFuture != null) {
        responseFuture.setResponseCommand(cmd);

        responseFuture.release();

        responseTable.remove(opaque);

        if (responseFuture.getInvokeCallback() != null) {
            executeInvokeCallback(responseFuture);
        } else {
            responseFuture.putResponse(cmd);
        }
    } else {
        PLOG.warn("receive response, but not matched any request, " + RemotingHelper.parseChannelRemoteAddr(ctx.channel()));
        PLOG.warn(cmd.toString());
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:26,代码来源:NettyRemotingAbstract.java

示例10: start

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
public static BrokerController start(BrokerController controller) {
    try {
        controller.start();
        String tip = "The broker[" + controller.getBrokerConfig().getBrokerName() + ", "
            + controller.getBrokerAddr() + "] boot success. serializeType=" + RemotingCommand.getSerializeTypeConfigInThisServer();

        if (null != controller.getBrokerConfig().getNamesrvAddr()) {
            tip += " and name server is " + controller.getBrokerConfig().getNamesrvAddr();
        }

        log.info(tip);
        return controller;
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(-1);
    }

    return null;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:20,代码来源:BrokerStartup.java

示例11: notifyConsumerIdsChanged

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
public void notifyConsumerIdsChanged(
    final Channel channel,
    final String consumerGroup) {
    if (null == consumerGroup) {
        log.error("notifyConsumerIdsChanged consumerGroup is null");
        return;
    }

    NotifyConsumerIdsChangedRequestHeader requestHeader = new NotifyConsumerIdsChangedRequestHeader();
    requestHeader.setConsumerGroup(consumerGroup);
    RemotingCommand request =
        RemotingCommand.createRequestCommand(RequestCode.NOTIFY_CONSUMER_IDS_CHANGED, requestHeader);

    try {
        this.brokerController.getRemotingServer().invokeOneway(channel, request, 10);
    } catch (Exception e) {
        log.error("notifyConsumerIdsChanged exception, " + consumerGroup, e.getMessage());
    }
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:20,代码来源:Broker2Client.java

示例12: createRemotingServer

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
public static RemotingServer createRemotingServer() throws InterruptedException {
    NettyServerConfig config = new NettyServerConfig();
    RemotingServer remotingServer = new NettyRemotingServer(config);
    remotingServer.registerProcessor(0, new NettyRequestProcessor() {
        @Override
        public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) {
            request.setRemark("Hi " + ctx.channel().remoteAddress());
            return request;
        }

        @Override
        public boolean rejectRequest() {
            return false;
        }
    }, Executors.newCachedThreadPool());

    remotingServer.start();

    return remotingServer;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:21,代码来源:RemotingServerTest.java

示例13: wipeWritePermOfBroker

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
private RemotingCommand wipeWritePermOfBroker(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(WipeWritePermOfBrokerResponseHeader.class);
    final WipeWritePermOfBrokerResponseHeader responseHeader = (WipeWritePermOfBrokerResponseHeader) response.readCustomHeader();
    final WipeWritePermOfBrokerRequestHeader requestHeader =
        (WipeWritePermOfBrokerRequestHeader) request.decodeCommandCustomHeader(WipeWritePermOfBrokerRequestHeader.class);

    int wipeTopicCnt = this.namesrvController.getRouteInfoManager().wipeWritePermOfBrokerByLock(requestHeader.getBrokerName());

    log.info("wipe write perm of broker[{}], client: {}, {}",
        requestHeader.getBrokerName(),
        RemotingHelper.parseChannelRemoteAddr(ctx.channel()),
        wipeTopicCnt);

    responseHeader.setWipeTopicCount(wipeTopicCnt);
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:19,代码来源:DefaultRequestProcessor.java

示例14: queryCorrectionOffset

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
private RemotingCommand queryCorrectionOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    QueryCorrectionOffsetHeader requestHeader =
        (QueryCorrectionOffsetHeader) request.decodeCommandCustomHeader(QueryCorrectionOffsetHeader.class);

    Map<Integer, Long> correctionOffset = this.brokerController.getConsumerOffsetManager()
        .queryMinOffsetInAllGroup(requestHeader.getTopic(), requestHeader.getFilterGroups());

    Map<Integer, Long> compareOffset =
        this.brokerController.getConsumerOffsetManager().queryOffset(requestHeader.getTopic(), requestHeader.getCompareGroup());

    if (compareOffset != null && !compareOffset.isEmpty()) {
        for (Map.Entry<Integer, Long> entry : compareOffset.entrySet()) {
            Integer queueId = entry.getKey();
            correctionOffset.put(queueId,
                correctionOffset.get(queueId) > entry.getValue() ? Long.MAX_VALUE : correctionOffset.get(queueId));
        }
    }

    QueryCorrectionOffsetBody body = new QueryCorrectionOffsetBody();
    body.setCorrectionOffsets(correctionOffset);
    response.setBody(body.encode());
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:27,代码来源:AdminBrokerProcessor.java

示例15: testInvokeAsync

import org.apache.rocketmq.remoting.protocol.RemotingCommand; //导入依赖的package包/类
@Test
public void testInvokeAsync() throws InterruptedException, RemotingConnectException,
    RemotingTimeoutException, RemotingTooMuchRequestException, RemotingSendRequestException {

    final CountDownLatch latch = new CountDownLatch(1);
    RemotingCommand request = RemotingCommand.createRequestCommand(0, null);
    request.setRemark("messi");
    remotingClient.invokeAsync("localhost:8888", request, 1000 * 3, new InvokeCallback() {
        @Override
        public void operationComplete(ResponseFuture responseFuture) {
            latch.countDown();
            assertTrue(responseFuture != null);
            assertThat(responseFuture.getResponseCommand().getLanguage()).isEqualTo(LanguageCode.JAVA);
            assertThat(responseFuture.getResponseCommand().getExtFields()).hasSize(2);
        }
    });
    latch.await();
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:19,代码来源:RemotingServerTest.java


注:本文中的org.apache.rocketmq.remoting.protocol.RemotingCommand类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。