Skip to content

AlibabaDubboServiceBeanListener #4157

@wzhangNJ

Description

@wzhangNJ

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

hi,
shgenyu: 2.5.0
dubbo:2.6.2
issue:
Map<String, ServiceBean> serviceBean = contextRefreshedEvent.getApplicationContext().getBeansOfType(ServiceBean.class);
serviceBean.size() = 0

public void onApplicationEvent(@NonNull final ContextRefreshedEvent contextRefreshedEvent) {
        if (!registered.compareAndSet(false, true)) {
            return;
        }
        // Fix bug(https://github.com/apache/shenyu/issues/415), upload dubbo metadata on ContextRefreshedEvent
        Map<String, ServiceBean> serviceBean = contextRefreshedEvent.getApplicationContext().getBeansOfType(ServiceBean.class);
        for (Map.Entry<String, ServiceBean> entry : serviceBean.entrySet()) {
            handler(entry.getValue());
        }
        serviceBean.values()
                .stream()
                .findFirst()
                .ifPresent(bean -> publisher.publishEvent(buildURIRegisterDTO(bean)));
    }

Expected Behavior

Feign used,ContextRefreshedEvent is created multiple times.

 if (!registered.compareAndSet(false, true)) {
            return;
        }

First Feign ApplicationContext be triggered, registered is true.
in the future , otherv ApplicationContext may not be triggered.

public void onApplicationEvent(@NonNull final ContextRefreshedEvent contextRefreshedEvent) {
        // Fix bug(https://github.com/apache/shenyu/issues/415), upload dubbo metadata on ContextRefreshedEvent
        Map<String, ServiceBean> serviceBean = contextRefreshedEvent.getApplicationContext().getBeansOfType(ServiceBean.class);
        for (Map.Entry<String, ServiceBean> entry : serviceBean.entrySet()) {
            handler(entry.getValue());
        }
        serviceBean.values()
                .stream()
                .findFirst()
                .ifPresent(bean -> publisher.publishEvent(buildURIRegisterDTO(bean)));
    }

Steps To Reproduce

No response

Environment

ShenYu version(s):2.6.0

Debug logs

No response

Anything else?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions