我使用WildFly 12.0 Final在域模式下构建群集,我还尝试使用群集API制作一个只包含有关群集的有用信息的日志文件。
创建了文件cluster.log,但它是空的。
我制作的课程如下:
package com.cluster.logger;
import java.util.List;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import org.jboss.logging.Logger;
import org.wildfly.clustering.group.GroupListener;
import org.wildfly.clustering.group.Membership;
import org.wildfly.clustering.group.Node;
@Singleton
@Startup
public class ClusterListener implements GroupListener
{
private static final Logger LOG = Logger.getLogger(ClusterListener.class);
@Override
public void membershipChanged(Membership previousMembership, Membership newMembership, boolean merged)
{
List<Node> previousNodes = previousMembership.getMembers();
LOG.infof("========================================");
LOG.infof("= Information about the previous nodes =");
for (Node node : previousNodes)
{
LOG.infof("Node name: " + node.getName());
LOG.infof("Node address: " + node.getSocketAddress());
}
LOG.infof("========================================");
List<Node> newNodes = newMembership.getMembers();
LOG.infof("========================================");
LOG.infof("=== Information about the new nodes ====");
for (Node node : newNodes)
{
LOG.infof("Node name: " + node.getName());
LOG.infof("Node address: " + node.getSocketAddress());
}
LOG.infof("========================================");
LOG.infof("Are they merged?: " + merged);
LOG.infof("========================================");
}
}
我还创建了一个自定义WildFly模块来配置此类,还修改了domain.xml中的日志记录子系统以处理所有内容,并且.jar文件与module.xml文件位于同一文件夹中。
这是module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.cluster.logger">
<resources>
<resource-root path="ClusterLogger.jar"/>
</resources>
<dependencies>
<module name="org.jboss.logging"/>
<module name="javax.api"/>
<module name="org.wildfly.clustering"/>
</dependencies>
</module>
这是domain.xml中的配置
<size-rotating-file-handler name="CLUSTER-LOG">
<formatter>
<named-formatter name="CLUSTER-PATTERN"/>
</formatter>
<file relative-to="jboss.home.dir" path="cluster.log"/>
<rotate-size value="10m"/>
<suffix value=".yyyy-MM-dd"/>
</size-rotating-file-handler>
...
<logger category="com.cluster.logger">
<level name="TRACE"/>
<handlers>
<handler name="CLUSTER-LOG"/>
</handlers>
</logger>
...
<formatter name="CLUSTER-PATTERN">
<pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
</formatter>
非常感谢任何帮助。
感谢。