Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

camellia-delay-queue support use nacos as register center #198

Open
caojiajun opened this issue Jan 3, 2024 · 4 comments
Open

camellia-delay-queue support use nacos as register center #198

caojiajun opened this issue Jan 3, 2024 · 4 comments
Labels
enhancement New feature or request feature

Comments

@caojiajun
Copy link
Collaborator

Module: camellia-delay-queue
Content: support use nacos as register center

@caojiajun caojiajun added enhancement New feature or request feature labels Jan 3, 2024
@firmianaQ
Copy link

请问现在的版本[1.2.28]有办法使用注册中心吗

@caojiajun
Copy link
Collaborator Author

当前支持eureka,其他注册中心需要简单开发一下

欢迎加入微信技术交流群

@firmianaQ
Copy link

firmianaQ commented Sep 4, 2024

当前支持eureka,其他注册中心需要简单开发一下

欢迎加入微信技术交流群

有示例吗?

@caojiajun
Copy link
Collaborator Author

服务器注册:
引入eureka依赖,配置发布即可

客户端发现:
实现DelayQueueServerDiscovery接口,在初始化CamelliaDelayQueueSdk时设置进去即可

参考:

public class EurekaDelayQueueServerDiscovery extends ReloadableCamelliaDiscovery<DelayQueueServer> implements DelayQueueServerDiscovery {

    private final DiscoveryClient discoveryClient;
    private final String applicationName;

    public EurekaDelayQueueServerDiscovery(DiscoveryClient discoveryClient, String applicationName, int refreshIntervalSeconds) {
        this.discoveryClient = discoveryClient;
        this.applicationName = applicationName;
        init(() -> new ArrayList<>(refreshProxySet()), refreshIntervalSeconds);
    }

    private Set<DelayQueueServer> refreshProxySet() {
        List<ServiceInstance> instances = discoveryClient.getInstances(applicationName);
        Set<DelayQueueServer> set = new HashSet<>();
        for (ServiceInstance instance : instances) {
            try {
                if (instance instanceof EurekaDiscoveryClient.EurekaServiceInstance) {
                    InstanceInfo instanceInfo = ((EurekaDiscoveryClient.EurekaServiceInstance) instance).getInstanceInfo();
                    if (instanceInfo.getStatus() != InstanceInfo.InstanceStatus.UP) {
                        continue;
                    }
                    set.add(new DelayQueueServer("http://" + instanceInfo.getIPAddr() + ":" + instanceInfo.getPort()));
                } else {
                    DelayQueueServer proxy = new DelayQueueServer("http://" + instance.getHost() + ":" + instance.getPort());
                    set.add(proxy);
                }
            } catch (Exception e) {
                DelayQueueServer proxy = new DelayQueueServer("http://" + instance.getHost() + ":" + instance.getPort());
                set.add(proxy);
            }
        }
        return set;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature
Projects
None yet
Development

No branches or pull requests

2 participants