Search in sources :

Example 96 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class DubboCodec method encodeRequestData.

@Override
protected void encodeRequestData(Channel channel, ObjectOutput out, Object data) throws IOException {
    RpcInvocation inv = (RpcInvocation) data;
    out.writeUTF(inv.getAttachment(Constants.DUBBO_VERSION_KEY, DUBBO_VERSION));
    out.writeUTF(inv.getAttachment(Constants.PATH_KEY));
    out.writeUTF(inv.getAttachment(Constants.VERSION_KEY));
    out.writeUTF(inv.getMethodName());
    out.writeUTF(ReflectUtils.getDesc(inv.getParameterTypes()));
    Object[] args = inv.getArguments();
    if (args != null)
        for (int i = 0; i < args.length; i++) {
            out.writeObject(encodeInvocationArgument(channel, inv, i));
        }
    out.writeObject(inv.getAttachments());
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation)

Example 97 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class FutureFilterTest method setUp.

@BeforeClass
public static void setUp() {
    invocation = new RpcInvocation();
    invocation.setMethodName("echo");
    invocation.setParameterTypes(new Class<?>[] { Enum.class });
    invocation.setArguments(new Object[] { "hello" });
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) BeforeClass(org.junit.BeforeClass)

Example 98 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project pinpoint by naver.

the class DubboConsumerInterceptor method before.

@Override
public void before(Object target, Object arg0) {
    Trace trace = this.getTrace(target);
    if (trace == null) {
        return;
    }
    RpcInvocation invocation = (RpcInvocation) arg0;
    if (trace.canSampled()) {
        SpanEventRecorder recorder = trace.traceBlockBegin();
        // RPC call trace have to be recorded with a service code in RPC client code range.
        recorder.recordServiceType(DubboConstants.DUBBO_CONSUMER_SERVICE_TYPE);
        // You have to issue a TraceId the receiver of this request will use.
        TraceId nextId = trace.getTraceId().getNextTraceId();
        // Then record it as next span id.
        recorder.recordNextSpanId(nextId.getSpanId());
        // Finally, pass some tracing data to the server.
        // How to put them in a message is protocol specific.
        // This example assumes that the target protocol message can include any metadata (like HTTP headers).
        invocation.setAttachment(DubboConstants.META_TRANSACTION_ID, nextId.getTransactionId());
        invocation.setAttachment(DubboConstants.META_SPAN_ID, Long.toString(nextId.getSpanId()));
        invocation.setAttachment(DubboConstants.META_PARENT_SPAN_ID, Long.toString(nextId.getParentSpanId()));
        invocation.setAttachment(DubboConstants.META_PARENT_APPLICATION_TYPE, Short.toString(traceContext.getServerTypeCode()));
        invocation.setAttachment(DubboConstants.META_PARENT_APPLICATION_NAME, traceContext.getApplicationName());
        invocation.setAttachment(DubboConstants.META_FLAGS, Short.toString(nextId.getFlags()));
    } else {
        // If sampling this transaction is disabled, pass only that infomation to the server.
        invocation.setAttachment(DubboConstants.META_DO_NOT_TRACE, "1");
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation)

Example 99 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project pinpoint by naver.

the class DubboConsumerInterceptor method after.

@Override
public void after(Object target, Object arg0, Object result, Throwable throwable) {
    Trace trace = this.getTrace(target);
    if (trace == null) {
        return;
    }
    RpcInvocation invocation = (RpcInvocation) arg0;
    try {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(descriptor);
        if (throwable == null) {
            String endPoint = RpcContext.getContext().getRemoteAddressString();
            // RPC client have to record end point (server address)
            recorder.recordEndPoint(endPoint);
            // Optionally, record the destination id (logical name of server. e.g. DB name)
            recorder.recordDestinationId(endPoint);
            recorder.recordAttribute(DubboConstants.DUBBO_ARGS_ANNOTATION_KEY, invocation.getArguments());
            recorder.recordAttribute(DubboConstants.DUBBO_RESULT_ANNOTATION_KEY, result);
        } else {
            recorder.recordException(throwable);
        }
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation)

Aggregations

RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)99 Test (org.junit.Test)73 URL (com.alibaba.dubbo.common.URL)60 ArrayList (java.util.ArrayList)43 Invoker (com.alibaba.dubbo.rpc.Invoker)35 Result (com.alibaba.dubbo.rpc.Result)29 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)22 RpcException (com.alibaba.dubbo.rpc.RpcException)22 Router (com.alibaba.dubbo.rpc.cluster.Router)12 MockInvoker (com.alibaba.dubbo.rpc.cluster.router.MockInvoker)11 List (java.util.List)10 Invocation (com.alibaba.dubbo.rpc.Invocation)9 RpcResult (com.alibaba.dubbo.rpc.RpcResult)8 Method (java.lang.reflect.Method)6 Protocol (com.alibaba.dubbo.rpc.Protocol)4 MockProtocol (com.alibaba.dubbo.rpc.support.MockProtocol)4 RemotingException (com.alibaba.dubbo.remoting.RemotingException)3 TimeoutException (com.alibaba.dubbo.remoting.TimeoutException)3 ExchangeClient (com.alibaba.dubbo.remoting.exchange.ExchangeClient)3 Request (com.alibaba.dubbo.remoting.exchange.Request)3