Closed nikotung closed 1 year ago
Do you mean that you want to inject MetadataService
into your bean?
No, I didn't want to do anything with MetadataService
. I write a custom filter injected a Spring bean on provider side and the provider starts up normally, the bean was successfully injected to the filter (not null). Also I have a consumer, during start-up this consumer will make a org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation#getMetadataInfo
request to the provider, I think this is by-design to get provider meta data. When the request come to the provider, it will first invoke the custom filter. The problem is that the Spring bean in the invoked custom filter is null
, it only be null
when the consumer request org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation#getMetadataInfo
. When I try to request our business interface this custom filter work as expected, no NullPointException
. Very time the consumer start up, it can reproduce. This is why I guest that the custom filter instanced twice.
@AlbumenJ You may check my demo here.
There are two Filter instance for MetadataService (Internal Services) and user-define services. Filter for internal serivces is useless and you can ignore it.
Thanks, now I know that the user-define Filter would be instanced twice, for Internal Services and User-define Services.
But I think the Filter should work exactly in both Internal Service and User-define Services, in my case, the Filter instance for Internal Service(MetadataService) was not injected a Spring bean via public void setBeanToInject(BeanToInject beanToInject)
method which caused a NullPointException
.
The reason is that spring context is on Dubbo module model level.
Ok. So now my question is how can I avoid or fix this NullPointException
? Or it's not a good idea to inject Spring bean in Dubbo3 via a setter
method?
Or it's not a good idea to inject Spring bean in Dubbo3 via a
setter
method?
It would be better to create a Factory
class for yourself.
Thanks. I think it would be great to write this in docs,like:
For the question "Dubbo consumer not register to Nacos", can you @AlbumenJ help to check. Here is the configuration:
dubbo:
application:
name: service-consumer-dubbo
register-mode: instance
service-discovery:
migration: FORCE_APPLICATION
parameters:
register-consumer-url: true
qos-enable: false
register-consumer: true
registry:
address: nacos://127.0.0.1:8848
parameters:
register-consumer-url: true
Dubbo3.0.0版本以后,增加了是否注册消费者的参数,如果需要将消费者注册到nacos注册中心上,需要将参数(register-consumer-url)设置为true,默认是false。
From the docs.
I specified the register-consumer-url
to true
, but still can't find the consumer in Nacos console.
In application service discovery mode, consumer node is no longer supported.
Environment
Steps to reproduce this issue
I created a demo to reproduce the issue.
While I tried to fix this issue #12078 , I found a
NullPointException
when the consumer start up and request toorg.apache.dubbo.registry.client.metadata.MetadataServiceDelegation#getMetadataInfo
service in the custom filter which injected a Spring bean successfully. ThisNullPointException
only happen when request to theMetadataService
, the other requests don't affect. It since likes there are two custom filter instances created for the same type.And I also found the consumer doesn't register to nacos with the following config, can't find the consumer instance on the nacos console.
Expected Behavior
Actual Behavior
MetadataService
.