Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build dubbogo and dubbo from scratch

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces how to build dubbogo and dubbo from scratch. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

The preface is based on dubbogo version 1.5.4.

Recently, I began to participate in some development tests of dubbogo, which used to directly use samples examples to verify the function, but this time, in order to reproduce a functional problem, I planned to build a project called dubbo-go and dubbo from scratch, stepped on some new people using dubbogo, and recorded this process for your reference.

Solve problem 1. Prepare dubbo service provider 1) basic definition

Define the DemoService interface:

Public interface DemoService {String sayHello (String name); String sayHello (User user); String sayHello (User user, String name);}

Define the User object:

Public class User implements Serializable {private String name; private int age;.} 2) start the dubbo service provider

The official sample code of dubbo used:

Public static void main (String [] args) throws IOException {/ / Service implementation DemoService demoService = new DemoServiceImpl (); / / current application configuration ApplicationConfig application = new ApplicationConfig (); application.setName ("demoProvider"); / / connection to registry configuration RegistryConfig registry = new RegistryConfig (); registry.setAddress ("127.0.0.1 2args"); registry.setProtocol ("zookeeper"); registry.setUsername ("") Registry.setPassword (""); / / Service provider protocol configuration ProtocolConfig protocol = new ProtocolConfig (); protocol.setName ("dubbo"); protocol.setPort (12345); protocol.setThreads (200C); / / Note: ServiceConfig is a heavy object, which internally encapsulates the connection to the registry, and opens the service port / / Service provider exposes service configuration ServiceConfig service = new ServiceConfig () / / this instance is very heavy, encapsulating the connection to the registry, please cache it yourself, otherwise memory and connection leakage may occur: service.setApplication (application); service.setRegistry (registry); / / multiple registries can use setRegistries () service.setProtocol (protocol); / / multiple protocols can use setProtocols () service.setInterface (DemoService.class); service.setRef (demoService) Service.setVersion ("1.0.0"); service.setGroup ("tc"); service.setTimeout (60 * 1000); / / exposure and registration service service.export (); System.in.read ();}

Check zookeeper to see if the registration is successful:

$ls / dubbo/com.funnycode.DemoService/providers [dubbo%3A%2F%2F127.0.0.1%3A12345%2Fcom.funnycode.DemoService%3Fanyhost%3Dtrue%26application%3DdemoProvider%26deprecated%3Dfalse%26dubbo%3D2.0.2%26dynamic%3Dtrue%26generic%3Dfalse%26group%3Dtc%26interface%3Dcom.funnycode.DemoService%26methods%3DsayHello%26pid%3D18167%26release%3D2.7.7%26revision%3D1.0.0%26side%3Dprovider%26threads%3D200%26timestamp%3D1606896020691%26version%3D1.0.0]

The output above indicates that the service provider has started.

two。 Prepare dubbogo service consumer 1) basic definition

Define the User object:

Type User struct {Name string Age int} func (User) JavaClassName () string {return "com.funnycode.User"}

Define the DemoProvider interface:

Type DemoProvider struct {SayHello func (ctx context.Context, name string) (string, error) `dubbo: "sayHello" `SayHello2 func (ctx context.Context, user User) (string, error) `dubbo: "sayHello" `SayHello3 func (ctx context.Context, user User, name string) (string Error) `dubbo: "sayHello" `} func (p * DemoProvider) Reference () string {return "DemoProvider"} 2) launch dubbogo consumer func main () {config.Load () gxlog.CInfo ("\ n\ n\ nstart to test dubbo") res, err: = demoProvider.SayHello (context.TODO () "tc") if err! = nil {panic (err)} gxlog.CInfo ("response result:% v\ n", res) user: = User {Name: "tc", Age: 18,} res, err = demoProvider.SayHello2 (context.TODO () User) if err! = nil {panic (err)} gxlog.CInfo ("response result:% v\ n", res) res, err = demoProvider.SayHello3 (context.TODO (), user, "tc") if err! = nil {panic (err)} gxlog.CInfo ("response result:% v\ n" Res) initSignal ()} 3. Request result analysis 1) call directly

Confirm the existence of the problem.

The parameter of the first API is a string, which can normally return [2020-12-03Universe 18 response result 59 main.main: client.go: 29] response result: Hello tc.

The second and third interfaces have User objects and cannot be called successfully. The error message is as follows:

2020-12-02T17:10:47.739+0800 INFO getty/listener.go:87 session {session session-closed, Read Bytes: 924,199, Read Pkgs: 0, Write Pkgs: 1} got error {java exception:Fail to decode request due to: java.lang.IllegalArgumentException: Service not found:com.funnycode.DemoService SayHello at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode (DecodeableRpcInvocation.java:134) at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode (DecodeableRpcInvocation.java:80) at org.apache.dubbo.remoting.transport.DecodeHandler.decode (DecodeHandler.java:57) at org.apache.dubbo.remoting.transport.DecodeHandler.received (DecodeHandler.java:44) at org.apache.dubbo.remoting.transport.dispatcher .ChannelEventRunnable.run (ChannelEventRunnable.java:57) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624) at java.lang.Thread.run (Thread.java:748)} Will be closed.

The error is exactly the same as described in issue. Because the error message is returned to the consumer side, you can see the error stack information on the Java side, so go directly to DecodeableRpcInvocation.decode#134.

2) breakpoint view

The code is as follows:

/ / deserialize public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Decodeable {public Object decode (Channel channel, InputStream input) throws IOException {. If (serviceDescriptor! = null) {/ / method description looks up MethodDescriptor methodDescriptor = serviceDescriptor.getMethod (getMethodName (), desc) based on the method name; if (methodDescriptor! = null) {pts = methodDescriptor.getParameterClasses (); this.setReturnTypes (methodDescriptor.getReturnTypes ()) }} / / means method if (pts = = DubboCodec.EMPTY_CLASS_ARRAY) {if (! RpcUtils.isGenericCall (path, getMethodName ()) & &! RpcUtils.isEcho (path, getMethodName ()) {throw new IllegalArgumentException ("Service not found:" + path + "," + getMethodName ());} pts = ReflectUtils.desc2classArray (desc)) is not found. }. }}

Check the MethodDescriptor, that is, to find out whether the method exists, and if so, the ParameterClasses will be set up.

If the above is not found, pts = = DubboCodec.EMPTY_CLASS_ARRAY will satisfy the condition, and then determine whether it is a generalization call or an echo call. If not, the service cannot find a method error.

Desc is Ljava/lang/Object, and obviously there is no argument to the Object method, so it is bound to report an error.

Supplementary note: method query. * * the code is as follows:

Public MethodDescriptor getMethod (String methodName, String params) {Map methods = descToMethods.get (methodName); if (CollectionUtils.isNotEmptyMap (methods)) {return methods.get (params);} return null;}

Advantages: compared with the previous version, the meta-information of the method is cached, and it is understandable to trade space for time without using reflection to improve efficiency.

4. Solve the problem

Because you can't hold the code directly, you can see what the problem is by comparison.

1) start the dubbo service consumer

Start through api mode, refer to the official example. This is started to view the transfer content of the Java version.

Public static void main (String [] args) throws InterruptedException {/ / current application configuration ApplicationConfig application = new ApplicationConfig (); application.setName ("demoProvider2"); / / connection registry configuration RegistryConfig registry = new RegistryConfig (); registry.setAddress ("127.0.0.1 args 2181"); registry.setProtocol ("zookeeper"); registry.setUsername (""); registry.setPassword ("") / / Note: ReferenceConfig is a heavy object, and internally encapsulates the connection to the registry, as well as the connection to the service provider / / reference remote service ReferenceConfig reference = new ReferenceConfig (); / / this instance is heavy, encapsulating the connection to the registry and the connection to the provider, please cache it yourself, otherwise it may cause memory and connection leakage reference.setApplication (application); reference.setRegistry (registry) / / multiple registries can use setRegistries () reference.setInterface (DemoService.class); reference.setVersion ("1.0.0"); reference.setGroup ("tc"); reference.setCheck (true); reference.setTimeout (1000 * 60); / / like local bean, xxxService DemoService demoService = reference.get () / / Note: all communication details are encapsulated inside this proxy object. The object is heavy. Please cache and reuse System.out.println (demoService.sayHello ("tc", 18)); TimeUnit.MINUTES.sleep (10);}

Desc visible to the naked eye is Lcom/funnycode/User, and this is the right object.

2) find out why dubbogo is wrong

Code location: protocol/dubbo/impl/hessian.go:120#marshalRequest

Code implementation:

Func marshalRequest (encoder * hessian.Encoder, p DubboPackage) ([] byte, error) {service: = p.Service request: = EnsureRequestPayload (p.Body) encoder.Encode (DEFAULT_DUBBO_PROTOCOL_VERSION) encoder.Encode (service.Path) encoder.Encode (service.Version) encoder.Encode (service.Method) args Ok: = request.Params. ([] interface {}) if! ok {logger.Infof ("request args are:% + v", request.Params) return nil, perrors.Errorf ("@ params is not of type: [] interface {}")} types, err: = getArgsTypeList (args) if err! = nil {return nil, perrors.Wrapf (err) "PackRequest (args:%+v)", args)} encoder.Encode (types) for _, v: = range args {encoder.Encode (v)}.}

The breakpoint can be found that when types returns, it is already Object, and no User is returned, so continue to look at the code.

Protocol/dubbo/impl/hessian.go:394#getArgsTypeList

Protocol/dubbo/impl/hessian.go:418#getArgType

Func getArgType (v interface {}) string {/ / common type handling. Default: t: = reflect.TypeOf (v) if reflect.Ptr = = t.Kind () {t = reflect.TypeOf (reflect.ValueOf (v). Elem ())} switch t.Kind () {case reflect.Struct: return "java.lang.Object"}.}

Obviously java.lang.Object is returned when it is found to be reflect.Struct, so the parameter becomes Object, so the call fails because the Java code depends on this type.

3) Verification of other versions

Because the feedback is 2.7.7 error, we first consider whether the previous version works properly, so switch the service provider to dubbo 2.7.3 and find that there are still errors in the call, as shown below:

2020-12-02T21:52:25.945+0800 INFO getty/listener.go:85 session {session session-closed, Read Bytes: 4586, Write Bytes: 4586, Read Pkgs: 0 Write Pkgs: 1} got error {java exception:org.apache.dubbo.rpc.RpcException: Failed to invoke remote proxy method sayHello to registry://127.0.0.1:2181/org.apache.dubbo.registry.RegistryService?application=demoProvider&dubbo=2.0.2&export=dubbo%3A%2F%2F192.168.0.113%3A12345%2Fcom.funnycode.DemoService%3Fanyhost%3Dtrue%26application%3DdemoProvider%26bind.ip%3D192.168.0.113%26bind.port%3D12345%26deprecated%3Dfalse%26dubbo%3D2.0.2 % 26dynamic%3Dtrue%26generic%3Dfalse%26group%3Dtc%26interface%3Dcom.funnycode.DemoService%26methods%3DsayHello%26pid%3D23889%26register%3Dtrue%26release%3D2.7.3%26revision%3D1.0.0%26side%3Dprovider%26threads%3D200%26timeout%3D60000%26timestamp%3D1606916702204%26version%3D1.0.0&pid=23889®istry=zookeeper&release=2.7.3×tamp=1606916702193 Cause: Not found method "sayHello" in class com.funnycode.DemoServiceImpl.org.apache.dubbo.rpc.RpcException: Failed to invoke remote proxy method sayHello to registry://127.0.0.1:2181/org.apache.dubbo.registry.RegistryService?application=demoProvider&dubbo=2.0.2&export=dubbo%3A%2F%2F192.168.0.113%3A12345%2Fcom.funnycode.DemoService%3Fanyhost%3Dtrue%26application%3DdemoProvider%26bind.ip%3D192.168.0.113%26bind.port%3D12345%26deprecated%3Dfalse%26dubbo% 3D2.0.2%26dynamic%3Dtrue%26generic%3Dfalse%26group%3Dtc%26interface%3Dcom.funnycode.DemoService%26methods%3DsayHello%26pid%3D23889%26register%3Dtrue%26release%3D2.7.3%26revision%3D1.0.0%26side%3Dprovider%26threads%3D200%26timeout%3D60000%26timestamp%3D1606916702204%26version%3D1.0.0&pid=23889®istry=zookeeper&release=2.7.3×tamp=1606916702193 Cause: Not found method "sayHello" in class com.funnycode.DemoServiceImpl. At org.apache.dubbo.rpc.proxy.AbstractProxyInvoker.invoke (AbstractProxyInvoker.java:107) at org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker.invoke (DelegateProviderMetaDataInvoker.java:56) at org.apache.dubbo.rpc.protocol.InvokerWrapper.invoke (InvokerWrapper.java:56) at org.apache.dubbo.rpc.filter.ExceptionFilter.invoke (ExceptionFilter.java:55) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke (ProtocolFilterWrapper.java:82) ) at org.apache.dubbo.monitor.support.MonitorFilter.invoke (MonitorFilter.java:92) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke (ProtocolFilterWrapper.java:82) at org.apache.dubbo.rpc.filter.TimeoutFilter.invoke (TimeoutFilter.java:48) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke (ProtocolFilterWrapper.java:82) at org.apache.dubbo.rpc.protocol.dubbo.filter. TraceFilter.invoke (TraceFilter.java:81) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke (ProtocolFilterWrapper.java:82) at org.apache.dubbo.rpc.filter.ContextFilter.invoke (ContextFilter.java:96) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke (ProtocolFilterWrapper.java:82) at org.apache.dubbo.rpc.filter.GenericFilter.invoke (GenericFilter.java:148) at org.apache.dubbo .rpc.filter .ProtocolFilterWrapper $1.invoke (ProtocolFilterWrapper.java:82) at org.apache.dubbo.rpc.filter.ClassLoaderFilter.invoke (ClassLoaderFilter.java:38) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke (ProtocolFilterWrapper.java:82) at org.apache.dubbo.rpc.filter.EchoFilter.invoke (EchoFilter.java:41) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke (ProtocolFilterWrapper.java:82) at Org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$CallbackRegistrationInvoker.invoke (ProtocolFilterWrapper.java:157) at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply (DubboProtocol.java:152) at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest (HeaderExchangeHandler.java:102) at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received (HeaderExchangeHandler.java:193) at org.apache.dubbo.remoting.transport. DecodeHandler.received (DecodeHandler.java:51) at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run (ChannelEventRunnable.java:57) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624) at java.lang.Thread.run (Thread.java:748) Caused by: org.apache.dubbo.common.bytecode.NoSuchMethodException: Not found method "sayHello" in class com.funnycode.DemoServiceImpl At org.apache.dubbo.common.bytecode.Wrapper1.invokeMethod (Wrapper1.java) at org.apache.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke (JavassistProxyFactory.java:47) at org.apache.dubbo.rpc.proxy.AbstractProxyInvoker.invoke (AbstractProxyInvoker.java:84)... 27 more}, will be closed.

Although it is different from the code in 2.7.7, you can see through the error that the method can not be found in the agent enhancement class, and the high probability is that the reflection can not find the method, so in the final analysis, it is also a problem of parameters.

4) fix the problem

The fix is relatively simple, which is to get the JavaClassName defined by struct.

Case reflect.Struct: v, ok: = v. (hessian.POJO) if ok {return v.JavaClassName ()} return "java.lang.Object" 5) Verification result

Execute the consumer again, running (provider 2.7.7 and 2.7.3) is normal, and the output is as follows:

[2020-12-03 client.go: 29] response result: Hello tc... [2020-12-03 main.main: client.go: 41] response result: Hello tc You are 18... [2020-12-03 client.go: 48] response result: Hello tc You are 18 details. How to configure dubbogo consumers

Have you noticed carefully that the consumer interface of my dubbogo is called DemoProvider, and then the provider is called DemoService? how does this work?

In fact, it has something to do with the configuration item references in client.yml. Interface,version,group is specified in the configuration file, and you can also configure the timeout of the method through methods and other information.

References: "DemoProvider": # you can specify multiple registry separated by commas; do not specify default registration with all registries registry: "zk1" protocol: "dubbo" interface: "com.funnycode.DemoService" cluster: "failover" version: "1.0.0" group: "tc" methods:-name: "SayHello" retries: 3..2. How to configure global group and version

The configuration file is as follows:

# application configapplication: organization: "dubbogoproxy.com" name: "Demo Micro Service" module: "dubbogoproxy tc client" version: "1.0.0" group: "tc" owner: "ZX" environment: "dev" references: "DemoProvider": # multiple registry can be specified, separated by commas Do not specify default registration with all registries registry: "zk1" protocol: "dubbo" interface: "com.funnycode.DemoService" cluster: "failover" # version: "1.0.0" # group: "tc" methods:-name: "SayHello" retries: 3

In terms of usage, application must represent the global configuration, but I found that the version and group configured in application at startup will not be assigned to the interface. Startup will report that the provider cannot find it, as follows:

2020-12-03T20:15:42.208+0800 DEBUG zookeeper/registry.go:237 Create a zookeeper node:/dubbo/com.funnycode.DemoService/consumers/consumer%3A%2F%2F30.11.176.107%2FDemoProvider%3Fapp.version%3D1.0.0%26application%3DDemo+Micro+Service%26async%3Dfalse%26bean.name%3DDemoProvider%26cluster%3Dfailover%26environment%3Ddev%26generic%3Dfalse%26group%3D%26interface%3Dcom.funnycode.DemoService%26ip%3D30.11.176.107%26loadbalance%3D%26methods. SayHello.loadbalance%3D%26methods.SayHello.retries%3D3%26methods.SayHello.sticky%3Dfalse%26module%3Ddubbogoproxy+tc+client%26name%3DDemo+Micro+Service%26organization%3Ddubbogoproxy.com%26owner%3DZX%26pid%3D38692%26protocol%3Ddubbo%26provided-by%3D%26reference.filter%3Dcshutdown%26registry.role%3D0%26release%3Ddubbo-golang-1.3.0%26retries%3D%26side%3Dconsumer%26sticky%3Dfalse%26timestamp%3D1606997742%26version%3D

Both version and group are empty. You must open the version and group comments under DemoProvider.

3. How to specify the method name of the call 1) go calls java

Dubbogo calls dubbo. Because go is an uppercase method name and java is a lowercase method name, the following error occurs:

2020-12-02T17:10:47.739+0800 INFO getty/listener.go:87 session {session session-closed, Read Bytes: 924,199, Read Pkgs: 0, Write Pkgs: 1} got error {java exception:Fail to decode request due to: java.lang.IllegalArgumentException: Service not found:com.funnycode.DemoService, SayHellojava.lang.IllegalArgumentException: Service not found:com.funnycode.DemoService SayHello at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode (DecodeableRpcInvocation.java:134) at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode (DecodeableRpcInvocation.java:80) at org.apache.dubbo.remoting.transport.DecodeHandler.decode (DecodeHandler.java:57) at org.apache.dubbo.remoting.transport.DecodeHandler.received (DecodeHandler.java:44) at org.apache.dubbo.remoting.transport.dispatcher .ChannelEventRunnable.run (ChannelEventRunnable.java:57) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624) at java.lang.Thread.run (Thread.java:748)} Will be closed.

Careful readers may have noticed that my interface declaration on the consumer side has a dubbo: "sayHello", indicating that the method name is sayHello, so that the method name sayHello can be obtained at the service provider.

And the three methods I have declared all indicate that their methods are called dubbo: "sayHello" because Java can be overloaded like method names, and go cannot be duplicated.

2) go calls go

Directly post the code that can run through.

My provider interface:

Type DemoProvider struct {} func (p * DemoProvider) SayHello (ctx context.Context, name string) (string, error) {return "Hello" + name, nil} func (p * DemoProvider) SayHello4 (ctx context.Context, user * User) (string, error) {return "Hello" + user.Name + "You are" + strconv.Itoa (user.Age), nil} func (p * DemoProvider) SayHello5 (ctx context.Context, user * User, name string) (string Error) {return "Hello" + name + "You are" + strconv.Itoa (user.Age), nil} func (p * DemoProvider) Reference () string {return "DemoProvider"} func (p * DemoProvider) MethodMapper () map [string] string {"SayHello": "sayHello",}}

My consumer interface:

Type DemoProvider struct {/ / call java and go SayHello func (ctx context.Context, name string) (string, error) `dubbo: "sayHello" `/ / only call java SayHello2 func (ctx context.Context, user * User) (string, error) `dubbo: "sayHello" `SayHello3 func (ctx context.Context, user * User, name string) (string Error) `dubbo: "sayHello" `/ / only call go SayHello4 func (ctx context.Context, user * User) (string, error) SayHello5 func (ctx context.Context, user * User, name string) (string, error)}

Start the service consumer:

Func main () {config.Load () gxlog.CInfo ("\ n\ n\ nstart to test dubbo") res, err: = demoProvider.SayHello (context.TODO (), "tc") if err! = nil {panic (err)} gxlog.CInfo ("response result:% v\ n", res) user: = & User {Name: "tc" Age: 18,} res, err = demoProvider.SayHello4 (context.TODO (), user) if err! = nil {panic (err)} gxlog.CInfo ("response result:% v\ n", res) res, err = demoProvider.SayHello5 (context.TODO (), user) "tc") if err! = nil {panic (err)} gxlog.CInfo ("response result:% v\ n", res) initSignal ()}

You need to pay attention to the MethodMapper method here, and sometimes you need to configure the mapping of the method name in this method, otherwise there will still be an error that the method cannot be found.

For example, if the request SayHello in go becomes sayHello because the dubbo: "sayHello" is configured, then the provider uses the MethodMapper method to configure it so that the provider is also sayHello, so that lowercase sayHello is exposed under both go and java.

4. Why do you use hessian2

Veteran drivers all know that the default value of SPI mechanism in dubbo is hessian2.

@ SPI ("hessian2") public interface Serialization {}

In dubbo-go:

Func NewDubboCodec (reader * bufio.Reader) * ProtocolCodec {s, _: = GetSerializerById (constant.S_Hessian2) return & ProtocolCodec {reader: reader, pkgType: 0, bodyLen: 0, headerRead: false, serializer: s. (Serializer),}} 5. Hessian serialization source code

You can check the breakpoint by yourself. The two sides are basically the same. I also compare them on both sides. RpcInvocation.getParameterTypesDesc () is the parameter of the method.

Go Code protocol/dubbo/impl/hessian.go:120#marshalRequest

Java code org.apache.dubbo.rpc.protocol.dubbo.DubboCodec#encodeRequestData (org.apache.dubbo.remoting.Channel, org.apache.dubbo.common.serialize.ObjectOutput, java.lang.Object, java.lang.String)

6. The method object of the dubbogo service provider needs to be a pointer object

The previous examples are all copy, this time is pure hand hit, just found this problem. If you provide something similar: func (p * DemoProvider) SayHello4 (ctx context.Context, user User) (string, error), the following error will occur:

2020-12-03T12:42:32.834+0800 ERROR getty/listener.go:280 OnMessage panic: reflect: Call using * main.User as type main.Usergithub.com/apache/dubbo-go/remoting/getty. (* RpcServerHandler) .OnMessage.func1

The User in the parameter needs to be changed to * User.

7. The method object of a dubbogo service consumer can be a non-pointer object SayHello4 func (ctx context.Context, user * User) (string, error) / / orSayHello4 func (ctx context.Context, user User) (string, error)

Because the pointer is manipulated when the parameter is serialized:

T: = reflect.TypeOf (v) if reflect.Ptr = = t.Kind () {t = reflect.TypeOf (reflect.ValueOf (v). Elem ())}

Complete code

8. Profile description

Dubbogo has three main configuration files:

Profile of the server.yaml service provider

The profile of the client.yaml service consumer

Log.yaml log file

If you do not configure anything, it will appear:

2021-01-11 15:31:41 [InitLog] warn: log configure file name is nil2021/01/11 15:31:41 [consumerInit] application configure (consumer) file name is nil2021/01/11 15:31:41 [providerInit] application configure (provider) file name is nil

It can't be used normally. If you are a service provider, you must configure server.yaml files, and if you are a service consumer, you must configure client.yaml. In fact, our application should be both a consumer and a provider, so often both files need to be configured.

The normal startup of the service provider will have the following output:

2021-01-11T15:36:55.003+0800 INFO protocol/protocol.go:205 The cached exporter keys is dubbo://:20000/DemoProvider?accesslog=&app.version=1.0.0&application=Demo+Micro+Service&auth=&bean.name=DemoProvider&cluster=failover&environment=dev&execute.limit=&execute.limit.rejected.handler=&group=tc&interface=com.funnycode.DemoService&loadbalance=random&methods.SayHello.loadbalance=random&methods.SayHello.retries=3&methods.SayHello.tps.limit.interval=&methods.SayHello.tps.limit.rate=&methods.SayHello.tps. Limit.strategy=&methods.SayHello.weight=0&methods.SayHello4.loadbalance=random&methods.SayHello4.retries=3&methods.SayHello4.tps.limit.interval=&methods.SayHello4.tps.limit.rate=&methods.SayHello4.tps.limit.strategy=&methods.SayHello4.weight=0&methods.SayHello5.loadbalance=random&methods.SayHello5.retries=3&methods.SayHello5.tps.limit.interval=&methods.SayHello5.tps.limit.rate=&methods.SayHello5.tps.limit.strategy=&methods.SayHello5.weight=0&module=dubbogoproxy+tc+client&name=Demo+Micro+Service&organization=dubbogoproxy.com&owner=ZX¶m.sign=& Registry.rolewings 3 released examples dubbokokogolangluo 1.3.0 examples serializationserializationinstalled service.filterechoes% 2Ctoken% 2Caccesslog% 2Ctps% 2Cgenericskills services% 2Cexecute% 2Cpshutdownsideprovidersslandenabledfalsestamps timestamp1610350614roomtps.room.rejected.handlerroomtps.room.room.flowers tps.room.cards. & app.version=1.0.0&application=Demo+Micro+Service&auth=&bean.name=DemoProvider&cluster=failover&environment=dev&execute.limit=&execute.limit.rejected.handler=&group=tc&interface=com.funnycode.DemoService&loadbalance=random&methods.SayHello.loadbalance=random&methods.SayHello.retries=3&methods.SayHello.tps.limit.interval=&methods.SayHello.tps.limit.rate=&methods.SayHello.tps.limit.strategy=&methods.SayHello.weight=0&methods.SayHello4.loadbalance=random&methods.SayHello4.retries=3&methods.SayHello4.tps.limit.interval=&methods.SayHello4.tps.limit .rate = & methods.SayHello4.tps.limit.strategy=&methods.SayHello4.weight=0&methods.SayHello5.loadbalance=random&methods.SayHello5.retries=3&methods.SayHello5.tps.limit.interval=&methods.SayHello5.tps.limit.rate=&methods.SayHello5.tps.limit.strategy=&methods.SayHello5.weight=0&module=dubbogoproxy+tc+client&name=Demo+Micro+Service&organization=dubbogoproxy.com&owner=ZX¶m.sign=®istry.role=3&release=dubbo-golang-1.3.0&retries=&serialization=&service.filter=echo%2Ctoken%2Caccesslog%2Ctps%2Cgeneric_service%2Cexecute%2Cpshutdown&side=provider&ssl -enabled=false×tamp=1610350614&tps.limit.interval=&tps.limit.rate=&tps.limit.rejected.handler=&tps.limit.strategy=&tps.limiter=&version=1.0.0&warmup=100, that's all about how to build dubbogo and dubbo from scratch. I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report