Thursday, June 10, 2010

How to Debug Apache Qpid Broker with Intellij IDEA

Apache Qpid/Java no longer has a Apache Maven build as it’s build system was moved to Apache Ant some time back for historical reasons. Therefore you can not do usual mvn idea:idea gimmick to generate IDEA project files. You can create an IDEA project from the scratch but it is unlikely someone would bother to do all that. So, the only viable solution is to use Remote debugging facility in IDEA. This is how you could go about doing this business.

Basically you need to start Qpid broker in debug mode – JPDA mode to be precise - and have your IDE connect to the remote JVM through an IDEA Remote Debug Configuration so that you will be hooked into the remote JVM and get triggered for the calls that are being made.

You can could start the Qpid broker in JPDA mode by passing the command line argument –run:jpda to your startup script. On windows it is qpid-server.bat –run:jpda. The broker will start as a JPDA listener. You can set the wire protocol transport using the JPDA_TRANSPORT environment variable that defaults to dt_socket. You could also use dt_shmem on Windows platforms in case you need to use the shared memory transport. You can set the address (port) using the JPDA_ADDRESS environment variable that defaults to 8000.

Since we do not have an IDEA project for Qpid, we just create an empty project and attach source to it. Once that is done you could follow the steps given below to setup the debugger to use JPDA.

1. Go to Run –> Edit Configurations

image 2. Add a new configuration instance of type Remote

image Set Transport depending on what you set in the broker startup script, Socket for the default case. Set Port accordingly, 8000 for the default case. You may also set the configuration instance name – Unnamed in the screen shot - and press OK.

3. Start your broker using the command qpid-server.bat -run:jpda

4. Launch debugger using Run –> Debug and you should see the following message in the IDEA console.

image 5. Set breakpoints as you wish and start debugging. Happy debugging! :-).

No comments: