I try to send and receive a netty ByteBuf message, but it fails.
What I'm doing wrong here? I even don't know ist he mistake in sending or 
receiving!
I was thinking to use the jms layer, but I'm receiving the data buffer throught 
a netty buffer and I want to avoid to convert the buffer to a byte array!

       public void sendMessageToSmtpQueue(ByteBuf buf) throws ActiveMQException 
{
             ClientSession session = this.sessionFactory.createSession();
             try {
                    session.start();
                    ClientMessage message = session.createMessage(true);
                    message.getBodyBuffer().writeBytes(buf, 0, 
buf.readableBytes());
                    ClientProducer producer = 
session.createProducer(ACTIVE_MQ_SMTP_QUEUE);
                    producer.send(message);
             } finally {
                    session.close();
             }
       }

       public ActiveMQBuffer receiveMessageFromSmtpQueue() throws 
ActiveMQException {
             ActiveMQBuffer result;
             ClientSession session = this.sessionFactory.createSession();
             try {
                    session.start();
                    ClientConsumer consumer = 
session.createConsumer(ACTIVE_MQ_SMTP_QUEUE);
                    ClientMessage message = consumer.receive();
                    result = 
ActiveMQBuffers.fixedBuffer(message.getBodyBufferSize());
                    message.getBodyBuffer().readBytes(result);
             } finally {
                    session.close();
             }

             return result;
       }


       public void startServer() throws Exception {
             this.configuration = new ConfigurationImpl();
             this.configuration.addAcceptorConfiguration("in-vm", 
ACTIVE_MQ_EMBEDDED_SERVER_URL);
             this.configuration.setPersistenceEnabled(true);
             this.configuration.setSecurityEnabled(false);
             this.configuration.addQueueConfiguration(new 
QueueConfiguration(ACTIVE_MQ_SMTP_QUEUE));

             this.server = new ActiveMQServerImpl(this.configuration);
             this.server.start();
       }

Reply via email to