Search in sources :

Example 1 with GetKVConfigResponseHeader

use of org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigResponseHeader in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MQClientAPIImpl method getKVConfigValue.

public String getKVConfigValue(final String namespace, final String key, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
    GetKVConfigRequestHeader requestHeader = new GetKVConfigRequestHeader();
    requestHeader.setNamespace(namespace);
    requestHeader.setKey(key);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_KV_CONFIG, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                GetKVConfigResponseHeader responseHeader = (GetKVConfigResponseHeader) response.decodeCommandCustomHeader(GetKVConfigResponseHeader.class);
                return responseHeader.getValue();
            }
        default:
            break;
    }
    throw new MQClientException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetKVConfigRequestHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigRequestHeader) MQClientException(org.apache.rocketmq.client.exception.MQClientException) GetKVConfigResponseHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigResponseHeader)

Example 2 with GetKVConfigResponseHeader

use of org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigResponseHeader in project rocketmq by apache.

the class DefaultRequestProcessor method getKVConfig.

public RemotingCommand getKVConfig(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(GetKVConfigResponseHeader.class);
    final GetKVConfigResponseHeader responseHeader = (GetKVConfigResponseHeader) response.readCustomHeader();
    final GetKVConfigRequestHeader requestHeader = (GetKVConfigRequestHeader) request.decodeCommandCustomHeader(GetKVConfigRequestHeader.class);
    String value = this.namesrvController.getKvConfigManager().getKVConfig(requestHeader.getNamespace(), requestHeader.getKey());
    if (value != null) {
        responseHeader.setValue(value);
        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);
        return response;
    }
    response.setCode(ResponseCode.QUERY_NOT_FOUND);
    response.setRemark("No config item, Namespace: " + requestHeader.getNamespace() + " Key: " + requestHeader.getKey());
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetKVConfigRequestHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigRequestHeader) GetKVConfigResponseHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigResponseHeader)

Example 3 with GetKVConfigResponseHeader

use of org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigResponseHeader in project rocketmq by apache.

the class DefaultRequestProcessorTest method testProcessRequest_GetKVConfigReturnNull.

@Test
public void testProcessRequest_GetKVConfigReturnNull() throws RemotingCommandException {
    GetKVConfigRequestHeader header = new GetKVConfigRequestHeader();
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_KV_CONFIG, header);
    request.addExtField("namespace", "namespace");
    request.addExtField("key", "key");
    RemotingCommand response = defaultRequestProcessor.processRequest(null, request);
    assertThat(response.getCode()).isEqualTo(ResponseCode.QUERY_NOT_FOUND);
    assertThat(response.getRemark()).isEqualTo("No config item, Namespace: namespace Key: key");
    GetKVConfigResponseHeader responseHeader = (GetKVConfigResponseHeader) response.readCustomHeader();
    assertThat(responseHeader.getValue()).isNull();
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetKVConfigRequestHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigRequestHeader) GetKVConfigResponseHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigResponseHeader) Test(org.junit.Test)

Example 4 with GetKVConfigResponseHeader

use of org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigResponseHeader in project rocketmq by apache.

the class MQClientAPIImpl method getKVConfigValue.

public String getKVConfigValue(final String namespace, final String key, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
    GetKVConfigRequestHeader requestHeader = new GetKVConfigRequestHeader();
    requestHeader.setNamespace(namespace);
    requestHeader.setKey(key);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_KV_CONFIG, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                GetKVConfigResponseHeader responseHeader = (GetKVConfigResponseHeader) response.decodeCommandCustomHeader(GetKVConfigResponseHeader.class);
                return responseHeader.getValue();
            }
        default:
            break;
    }
    throw new MQClientException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetKVConfigRequestHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigRequestHeader) MQClientException(org.apache.rocketmq.client.exception.MQClientException) GetKVConfigResponseHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigResponseHeader)

Example 5 with GetKVConfigResponseHeader

use of org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigResponseHeader in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultRequestProcessor method getKVConfig.

public RemotingCommand getKVConfig(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(GetKVConfigResponseHeader.class);
    final GetKVConfigResponseHeader responseHeader = (GetKVConfigResponseHeader) response.readCustomHeader();
    final GetKVConfigRequestHeader requestHeader = (GetKVConfigRequestHeader) request.decodeCommandCustomHeader(GetKVConfigRequestHeader.class);
    String value = this.namesrvController.getKvConfigManager().getKVConfig(requestHeader.getNamespace(), requestHeader.getKey());
    if (value != null) {
        responseHeader.setValue(value);
        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);
        return response;
    }
    response.setCode(ResponseCode.QUERY_NOT_FOUND);
    response.setRemark("No config item, Namespace: " + requestHeader.getNamespace() + " Key: " + requestHeader.getKey());
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetKVConfigRequestHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigRequestHeader) GetKVConfigResponseHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigResponseHeader)

Aggregations

GetKVConfigRequestHeader (org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigRequestHeader)8 GetKVConfigResponseHeader (org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigResponseHeader)8 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)8 Test (org.junit.Test)4 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2