简体   繁体   English

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

[英]Lookup of same EJB on multiple servers

I am trying to do a lookup from one deployment to another deployment, using exactle the same bean implementations. 我正在尝试从一个部署到另一个部署进行查找,使用相同的bean实现。 It is basically a consumer/producer setup with the same beans in both deployments on both machines. 它基本上是一个消费者/生产者设置,在两台机器上的两个部署中都使用相同的bean。

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

The ProducerBeanRemote should look up the ConsumerBeanRemote and call its public method. ProducerBeanRemote应该查找ConsumerBeanRemote并调用其公共方法。

Our machines are communicating like this: 我们的机器正在这样沟通:

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

You get the idea... 你明白了......

So the problem is, it doesn't work. 所以问题是,它不起作用。 I tried to do a manual lookup using the jboss-as-ejb-client libraries, which didn't work because JBoss locks the EJB selector while starting its container (AND I bet the spec has something to say about manual lookups in a Java EE environment). 我尝试使用jboss-as-ejb-client库进行手动查找,因为JBoss在启动其容器时锁定了EJB选择器,因此无法正常工作(我打赌规范在Java EE中有关于手动查找的说法环境)。 The next thing I tried was doing a lookup using the feature from Spring, to no avail. 我尝试的下一件事是使用Spring的功能进行查找,但无济于事。

We are using the JBoss Application Server 7.1.1.Final. 我们正在使用JBoss Application Server 7.1.1.Final。

I bet there has to be a way to accomplish my setup and I would greatly appreciate any help from the community. 我打赌必须有一种方法来完成我的设置,我将非常感谢社区的任何帮助。

UPDATE: 更新:

To connect from ProducerBeanRemote to ConsumerBeanRemote, we need the possibility to specify the remote InitialContext at runtime via configuration. 要从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);

The resulting exception is 由此产生的异常是

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

We understand that this exception is thrown because of https://issues.jboss.org/browse/AS7-2998 , so the question remains: How can we remotely call the same beans in a clean and configurable way? 我们知道由于https://issues.jboss.org/browse/AS7-2998引发了这个异常,所以问题仍然存在:我们如何以干净和可配置的方式远程调用相同的bean?

Nearly the same question as described here: JNDI lookup from one server to many configurable servers 几乎与此处描述的问题相同: 从一个服务器到多个可配置服务器的JNDI查找

It seems to be impossible to get a reliant connection between multiple servers via EJB, so we ended up using JMS for our server to server communication. 似乎不可能通过EJB获得多个服务器之间的依赖连接,因此我们最终使用JMS进行服务器到服务器的通信。 Maybe thats an option for you, too. 也许这也是你的选择。

The setup is possible. 设置是可能的。 There is no need to reengineer the whole code using JMS. 没有必要使用JMS重新设计整个代码。

It is possible to call remote ejb beans on different JBOSSAS7 servers from a single POJO client using your own custom Selector for the EJBClientContext. 可以使用您自己的EJBClientContext自定义选择器从单个POJO客户端调用不同JBOSSAS7服务器上的远程ejb bean。 With the code mentioned, you are able to register different scopes for different servers 使用上面提到的代码,您可以为不同的服务器注册不同的范围

See an example from the jboss developers here 请参阅jboss开发人员的示例

https://community.jboss.org/thread/223419?tstart=0 https://community.jboss.org/thread/223419?tstart=0

https://github.com/wfink/jboss-as-quickstart/blob/ejb-clients/ejb-clients/jboss-api/src/main/java/org/jboss/as/quickstarts/ejb/clients/selector/CustomScopeEJBClientContextSelector.java https://github.com/wfink/jboss-as-quickstart/blob/ejb-clients/ejb-clients/jboss-api/src/main/java/org/jboss/as/quickstarts/ejb/clients/selector/ CustomScopeEJBClientContextSelector.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM