通过 AMQ 核心协议 JMS,您可以拦截进入或退出客户端的数据包,允许您审核数据包或过滤消息。拦截器可以更改它们拦截的数据包。这使得拦截器功能强大,同时也是您应该谨慎使用的功能。
package com.example;
import org.apache.artemis.activemq.api.core.Interceptor;
import org.apache.activemq.artemis.core.protocol.core.Packet;
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
public class MyInterceptor implements Interceptor {
private final int ACCEPTABLE_SIZE = 1024;
@Override
boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
int size = packet.getPacketSize();
if (size <= ACCEPTABLE_SIZE) {
System.out.println("This Packet has an acceptable size.");
return true;
}
return false;
}
}
package com.example;
import org.apache.artemis.activemq.api.core.Interceptor;
import org.apache.activemq.artemis.core.protocol.core.Packet;
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
public class MyInterceptor implements Interceptor {
private final int ACCEPTABLE_SIZE = 1024;
@Override
boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
int size = packet.getPacketSize();
if (size <= ACCEPTABLE_SIZE) {
System.out.println("This Packet has an acceptable size.");
return true;
}
return false;
}
}
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow