Thursday, July 21, 2011

Rabbit MQ - spring-amqp : waiting response (RPC like style)

I 'm testing rabbitmq and spring-ampq for a prototype. I have to use rabbitmq in an "rpc style" for some communications. I find out and do the rpc rabbit-mq tutorial (here) and finally does the same thing with spring amqp.

In this work the only point was to implement an equivalent of  
QueueingConsumer consumer = new QueueingConsumer(channel);


I replace this object by my own implementation as i don't fonnd anything in spring-rabbit abstraction.

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;


import org.springframework.amqp.core.Address;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;


import com.rabbitmq.client.Channel;

public class ProducerMessageListener implements ChannelAwareMessageListener {
    ConnectionFactory connectionFactory;
    RemoteService callback;
   

    public BlockingQueue _queue = new LinkedBlockingQueue();
    

    public ProducerMessageListener(RemoteService callback, String corrid) {
        this.callback = callback;
    }



    public ConnectionFactory getConnectionFactory() {
        return connectionFactory;
    }

    public void setConnectionFactory(ConnectionFactory connectionFactory) {
        this.connectionFactory = connectionFactory;
    }

    

    public void onMessage(Message message, Channel channel) throws Exception {
        System.out.println("message receive on blocking process");
        try {
            Address adrs = message.getMessageProperties().getReplyTo();
            byte[] corrid = message.getMessageProperties().getCorrelationId();
            synchronized (_queue) {
                _queue.add(message);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


To use it 
ProducerMessageListener cml = new ProducerMessageListener(this, corrid);
cml.setConnectionFactory(rabbitConnectionFactory);
SimpleMessageListenerContainer asmlc = new SimpleMessageListenerContainer();
asmlc.setConnectionFactory(rabbitConnectionFactory);
asmlc.setQueueNames(replyto);
asmlc.setQueues(q);
asmlc.setMessageListener(cml);
asmlc.initialize();
asmlc.start();
       
rabbitTemplateConsumer.send(msg);
//wait on blocking queue
Message msgresponse=null;
try {
            msgresponse = cml._queue.take();
            System.out.println("got "+new String(msgresponse.getBody()));
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
       
//CARREFULL
// destroy asmlc when finish (gc..)
// destruction is time consumming so we does in thread
        new Thread(new Runnable() {
          
            @Override
            public void run() {
                    asmlc.stop();
                    asmlc.destroy();
              
            }
        }).start();
 
return new String(msgresponse.getBody());
}

Wednesday, June 29, 2011

Describing software architect job

I found a presentation about Software Architect Role.
In the whole (not always...) this presentation fit what I think about my job. Have a look if you have time.
Software (Solution) Architect role

free REST ebook

A few weeks ago i wrote many thing about REST and it's (miss)understanding.
As I navigate on software architecture I found an infoQ free book about REST. I didn't read all but what I red was enough interesting to write a small post about this.
this is the link REST emag, good reading !

Tuesday, June 7, 2011

light bug tracker

Few month ago we search a bug tracker for 10 to 15 user and internal use.
What we want :
  • simple installation (no/embedded RDBMS, running on tomcat 6.0)
  • simple tool (light to use and manage )
  • management of many workflow with many different steps
We found JTrac. This tools reply to all our needs. All The functionalities are here.
Have o look.

Wednesday, March 16, 2011

Distributed Version Control System (DVCS)

I'm currently looking for a DVCS for a new project. I found three tools :

  • mercurial
  • git
  • baazar
It's not easy to choose, and as usual I don't want to waste too much time in testing all three.

To go through the decision I found  many links :

at the end, I think, I will use mercurial and post if this tool does not fit. 

java encoding...

If you want to set java encoding to UTF-8 (or what ever you want...) you could use :

  • JAVA_TOOL_OPTIONS in you environment to set  file.encoding property with JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8  
  • starting your vm with -Dfile.encoding=UTF-8  argument
  • set the default encoding in your favorite IDE.


Wednesday, February 23, 2011

REST style

Last couple of days , I worked on a REST architecture. I never really worked on this architecture at the design level, I just applied some given rules during developments or maintenance. So I found this job very interesting.
My first surprise was to discover that a lot of people (including me) just take a  few REST characteristics  and claims to be "Restfull". In fact this is not a problem, but those people provide and promote something else that REST.
If you have time you could have a look at the Roy Thomas Fielding's phd thesis or you could have a look at the richardson maturity model. To be honest, the link that makes me realize what is really REST is this one : http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven.

The key points of REST :

  • ressources
  • hypermedia
  • server statelessness
In this list it seems thats hypermedia driven application is not well considered (accepted?). 
What ever read the previous link if what is preceding seems not clear.

Enjoy!