EAP 7:EJB状态未在群集模式下的有状态会话Bean之间复制

问题描述 投票:0回答:1

我运行了两个EAP 7.0实例,都有standalone-full-ha.xml

一个是从:

/opt/jboss-eap-7.0/bin/standalone.sh -Djboss.node.name=node1 -Djboss.server.base.dir=/opt/node1 -Djboss.messaging.cluster.password=message -c standalone-full-ha.xml

另一个用:

/opt/jboss-eap-7.0/bin/standalone.sh -Djboss.node.name=node2 -Djboss.server.base.dir=/opt/node2 -Djboss.messaging.cluster.password=message -c standalone-full-ha.xml -Djboss.socket.binding.port-offset=4

两者都从成功开始,我可以看到他们加入群集渠道:

[org.infinispan.remoting.transport.jgroups.JGroupsTransport] (MSC service thread 1-6) ISPN000078: Starting JGroups channel ejb
...
[org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 72) WFLYCLINF0002: Started eap.war cache from ejb container

我有一个有状态会话bean:

import javax.ejb.Stateful;

@Stateful
public class Counter {

    int counter;

    public int getCounter() {
        ++counter;
        return counter;
    }
}

一个JSF应用程序作用域bean:

import java.io.Serializable;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;

@ApplicationScoped
@Named
public class IndexBean implements Serializable {

    @Inject
    transient Counter counter;

    public int getCounter() {
        return counter.getCounter();
    }
}

一个JSF会话范围的bean:

import java.io.Serializable;

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@SessionScoped
@Named
public class SessionBean implements Serializable {

    int counter;

    public int getCounter() {
        ++counter;
        return counter;
    }

}

网络嗯:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" metadata-complete="false" version="3.1">
<distributable/>
</web-app>

和index.xhtml:

<html
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
    <title>EAP 7</title>
</h:head>
<h:body>
<h:outputText value="#{indexBean.counter}"></h:outputText>
<br />
<br />
<h:outputText value="#{sessionBean.counter}"></h:outputText>
</h:body>
</html>

现在,当我导航到localhost:8080 / index.xhtml上的node1时,我有一个带有两个以1开头的计数器的webppage。每次刷新页面时都会计数。

当我导航到localhost:8084 / index.xhtml上的node2时,我希望看到来自node1的最后一个递增值,但来自@Stateful bean的计数器不会从node1的值递增。

示例:导航到node1:

1
1

- >刷新node1

2
2

- >刷新node1

3
3

导航到node2:

1
4

- >刷新node2

2
5

再次刷新node1:

4
6

再次刷新node2:

3
8

这两个页面独立工作,但应该复制有状态会话bean之间的状态。我不明白为什么它不起作用。 @SessionScoped bean之间的状态总是被复制......

我正在寻找一些文档,发现这个:

https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html/developing_ejb_applications/clustered_enterprise_javabeans#cluster_topology_communication

这一点在8.2节末尾说明:

启动JBoss EAP 7,如果使用HA配置文件启动JBoss EAP,将复制SFSB的状态。

@Stateful bean需要更多配置吗?

infinispan jboss-eap-7 stateful-session-bean ejb-3.2
1个回答
0
投票

上面的代码存在的问题是,即使复制了状态本身,也不会在node1和node2之间共享@ApplicationScoped SFSB引用。

© www.soinside.com 2019 - 2024. All rights reserved.