gpt4 book ai didi

java - 在多个服务器上查找相同的 EJB

转载 作者:行者123 更新时间:2023-12-02 05:58:54 35 4
gpt4 key购买 nike

我正在尝试使用完全相同的 bean 实现从一个部署到另一个部署进行查找。它基本上是一个消费者/生产者设置,在两台机器上的部署中使用相同的 bean。

ear
ejb-api
com.example.bean
ConsumerBean
ProducerBean
ejb-jar
com.example.bean
ConsumerBeanRemote
ProducerBeanRemote

ProducerBeanRemote 应该查找 ConsumerBeanRemote 并调用其公共(public)方法。

我们的机器是这样通信的:

(Machine A) ProducerBeanRemote --> (Machine B) ConsumerBeanRemote
(Machine A) ProducerBeanRemote --> (Machine C) ConsumerBeanRemote
(Machine A) ProducerBeanRemote --> (Machine D) ConsumerBeanRemote

你明白了...

所以问题是,它不起作用。我尝试使用 jboss-as-ejb-client 库进行手动查找,但这不起作用,因为 JBoss 在启动其容器时锁定了 EJB 选择器(而且我敢打赌规范对 Java EE 中的手动查找有一些规定)环境)。我尝试的下一件事是使用 Spring 的功能进行查找,但没有成功。

我们正在使用 JBoss 应用程序服务器 7.1.1.Final。

我敢打赌一定有一种方法来完成我的设置,我将非常感谢社区的任何帮助。

更新:

要从 ProducerBeanRemote 连接到 ConsumerBeanRemote,我们需要能够在运行时通过配置指定远程 InitialContext。

Properties properties = new Properties();
properties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
properties.put("remote.connections", "default");
properties.put("remote.connection.default.host", "remote-host");
properties.put("remote.connection.default.port", "4447");
properties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");

EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(properties);
ContextSelector<EJBClientContext> ejbClientContextSelector = new ConfigBasedEJBClientContextSelector(ejbClientConfiguration);
EJBClientContext.setSelector(ejbClientContextSelector);

StatelessEJBLocator<T> locator = new StatelessEJBLocator<>(viewType, appName, moduleName, beanName, distinctName);
return EJBClient.createProxy(locator);

产生的异常是

java.lang.SecurityException: EJB client context selector may not be changed at org.jboss.ejb.client.EJBClientContext.setSelector(EJBClientContext.java:181)

据我们了解,引发此异常的原因是 https://issues.jboss.org/browse/AS7-2998 ,所以问题仍然存在:我们如何以干净且可配置的方式远程调用相同的 bean?

最佳答案

与此处描述的问题几乎相同:JNDI lookup from one server to many configurable servers

似乎不可能通过 EJB 在多个服务器之间建立可靠的连接,因此我们最终使用 JMS 进行服务器到服务器的通信。也许这也是您的一个选择。

关于java - 在多个服务器上查找相同的 EJB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22838876/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com