2

我们使用 Adob​​e CQ (5.5) 作为 CMS。现在,我们的 CQ 环境由一个作者服务器(用户可以在其中创建内容)和 2 个发布服务器(将内容提供到互联网)组成。

现在有一个复制代理将内容从作者服务器推送到两个发布服务器。不幸的是,有些文章阻塞了复制代理的队列,因此不再发布新内容。这不是什么大问题,因为它很容易修复。真正的问题是,直到用户开始抱怨没有发布更多更改时,我们才注意到这种阻塞。

我四处搜索,发现 CQ 提供了一个 JMX API,监控应用程序可以将自己附加到它。然后我试图找到一些允许我配置警报的开源软件,以便我们可以更快地做出反应,但我找不到任何东西。

这是我决定尝试编写自己的 Java 应用程序的时候,它只读取属性并在属性为真时发送邮件。我想这比我想象的要复杂。

首先,我不是 Java 开发人员,但由于 CQ 是基于 Java 的,所以我认为我会尝试一下。我阅读了一些关于 JMX 和 Java 的文档,并且能够获得到 CQ 服务器的有效连接。但这几乎是我能意识到的一切。

我发现该类com.adobe.granite.replication有一个类型agent,它为每个复制代理存储一个 id(例如,id 是复制代理的名称id=replication-publish-1)。每个复制代理都有不同的属性,但与我相关的属性是“QueueBlocked”。

这是我到目前为止的代码(它基于这个例子):

public static void main(String[] args) {
    try {
        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://servername:9010/jmxrmi");
        JMXConnector jmxc = JMXConnectorFactory.connect(url, null);

        ClientListener listener = new ClientListener();

        MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

        // This outputs the domains, one of them is com.adobee.granite.replication, the one which I need to use
        // This is why I'm sure that at least the connection works, I don't have any com.adobe.granite.replication class on my Eclipse installation, so the output has to come from the server
        String domains[] = mbsc.getDomains();
        for (int i = 0; i < domains.length; i++) {
            echo("\tDomain[" + i + "] = " + domains[i]);
        }

        ObjectName replication = new ObjectName("com.adobe.granite.replication:type=Agent,id=replication-publish-1");

        mbsc.getAttribute(replication, "QueueBlocked"); // This throws the error
} catch(Exception e) {

}

}

抛出的错误如下:

javax.management.InstanceNotFoundException: com.adobe.granite.replication:type=Agent,id=replication-publish-1

据我了解,我应该创建某种实例,但我真的不知道什么实例以及如何创建它。无论是文档还是代码片段,我都非常感谢我能得到的任何帮助:)

4

1 回答 1

5

解决了:)

这是我正在使用的代码:

import java.io.IOException;
import java.util.Iterator;
import java.util.Set;
import javax.management.Attribute;
import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

public class Client {

    public static void main(String[] args) {
        try {
            JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://servername:9010/jmxrmi");
            JMXConnector jmxc = JMXConnectorFactory.connect(url, null);

            MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

            ObjectName replication1 = new ObjectName("com.adobe.granite.replication:type=agent,id=\"replication-publish-1\"");
            ObjectName replication2 = new ObjectName("com.adobe.granite.replication:type=agent,id=\"replication-publish-2\"");

            String replication1Status = mbsc.getAttribute(replication1, "QueuePaused").toString();
            String replication2Status = mbsc.getAttribute(replication2, "QueuePaused").toString();



        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
于 2013-04-18T13:00:46.970 回答