Intercept packets leaving the server?
sirrichie Nov 11, 2010 8:34 AMHi everyone!
I am using HornetQ for a research project and would like to intercept packets that leave the server.
I have already found the Interceptor interface and successfully ran the example and an experimental interceptor of my own.
The issue I have is that the interceptor does not seem to intercept messages that leave the server.
For example: I want a certain client with a certain IP address not to receive packets that have the property "classified" set to true.
From looking at the org.hornetq.core.protocol.core.impl.wireformat package, I assume that at some point a SessionReceiveMessage packet would be produced and sent to the consumer. However, the interceptor only indicates that a SessionSendMessage passed by.
My interceptor looks like this:
public class TestInterceptor implements Interceptor
{
/* (non-Javadoc)
* @see org.hornetq.api.core.Interceptor#intercept(org.hornetq.core.protocol.core.Packet, org.hornetq.spi.core.protocol.RemotingConnection)
*/
public boolean intercept(Packet packet, RemotingConnection connection) throws HornetQException
{
System.out.println("Packet: " + packet.getClass().getSimpleName() + " @ " + connection.getRemoteAddress());
return true;
}
}
The producer code looks like this:
try {
// setup client
ClientSessionFactory factory = HornetQClient
.createClientSessionFactory(new TransportConfiguration(
NettyConnectorFactory.class.getName()));
ClientSession session = factory.createSession();
ClientProducer producer = session.createProducer("interceptor");
session.start();
InputStreamReader inp = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(inp);
// read from standard in and send user input to the server
String input;
while (!("exit").equals((input = br.readLine()))) {
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeString(input);
producer.send(message);
}
session.close();
} catch (HornetQException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
And the consumer code:
try {
ClientSessionFactory factory = HornetQClient
.createClientSessionFactory(new TransportConfiguration(
NettyConnectorFactory.class.getName()));
ClientSession session = factory.createSession();
session.createQueue("interceptor", "interceptor", false);
ClientConsumer consumer = session.createConsumer("interceptor");
session.start();
while (receive) {
ClientMessage msg = consumer.receive();
printMessage(msg);
}
session.close();
} catch (HornetQException e) {
e.printStackTrace();
}
The output I get at the server side when starting the consumer, then the producer and finally sending a message (i.e. typing something on standard-in):
[java] Packet: Ping @ /127.0.0.1:56774
[java] Packet: CreateSessionMessage @ /127.0.0.1:56774
[java] Packet: CreateQueueMessage @ /127.0.0.1:56774
[java] Packet: SessionCreateConsumerMessage @ /127.0.0.1:56774
[java] Packet: SessionConsumerFlowCreditMessage @ /127.0.0.1:56774
[java] Packet: PacketImpl @ /127.0.0.1:56774
[java] Packet: Ping @ /127.0.0.1:56775
[java] Packet: CreateSessionMessage @ /127.0.0.1:56775
[java] Packet: SessionRequestProducerCreditsMessage @ /127.0.0.1:56775
[java] Packet: PacketImpl @ /127.0.0.1:56775
[java] Packet: SessionSendMessage @ /127.0.0.1:56775
With all messages except the first coming from the initalization phase (i.e. starting consumer and producer)
I tried searching the forums and bug trackers, but I have not found anything describing this problem. So I'm wondering if I am missing something or if this is indeed a bug?