J’s Blog

XMS.Net Consumer Application for IBM WebSphere MQ

Posted by: Jawaid on: 29 October 2009

Currently we are working on IBM WebSphere MQ to be used in our project. One feature that we need from several features of WebSphere MQ was to subscribe to a topic with selector string from a C#.Net application. IBM provides two libraries for .Net. One is MQI classes for .Net and another is XMS.Net (IBM Message Service Client for .Net). Finally we adopted XMS.Net, although we also tried MQI classes for .Net, but we moved to XMS.Net. Its totally a different story why we moved to XMS.Net. I might write another post on it :)

So, at first place we tried to run sample consumer application came with XMS.Net library. Our center of the focus was selector string. When we were trying to run the sample consumer application and supplied the topic to subscribe to and selector string to filter the messages, it was getting stuck every time after subscription. Even it wasn’t receiving any messages, although we could see the subscription object being created on the WMQ server. One thing that we were doing was that we were running the sample in ‘client’ mode. When we switched the mode to ‘unmanaged’, everything ran smoothly. We were bit surprised! Why it wasn’t running in client mode? I think there is some bug, since I couldn’t find anything related in the docs. Might IBM will fix this issue in the future release.  But at last, somehow we managed to run the sample consumer application and finally we are at the stage where we can move forward.

So, if you are also trying to run XMS.Net application and want to subscribe to some topic with selector string to filter messages, remember to run the application in ‘unmanaged’ mode. You can find further information in XMS.Net doc (ftp://ftp.software.ibm.com/software/integration/support/supportpacs/individual/ia9h.pdf).

Useful vim options for techies

Posted by: Jawaid on: 7 August 2009

Vim is very useful tool for editing files, especially for techies to edit configuration and code files. There are some useful options for them in vim. You can set them in the vim configuration file vimrc usually found in /etc. Here are some of those options:

syntax on            " Turn on syntax highlighting
set incsearch        " Used for incremental searching
set hlsearch         " Turns on highlighting for matched search patterns
set tabstop=4        " Sets the tab size to 4
set shiftwidth=4     " Sets spaces used for (auto)indent
set shiftround       " Indent to nearest tabstop
set autoindent       " Carries over previous indent to the next line

Note: Double quotes (“) are used for comments.

I was having some issues installing MQSeries Perl Extension 1.29 for IBM WebSphere MQ (WMQ). What actually I did was downloaded the MQSeries module from the CPAN, extracted it and ran the perl Makefile.PL. But it gave me the following error:

> perl Makefile.PL
Checking if your kit is complete…
Looks good
ERROR from evaluation of /root/MQSeries-1.29/MQClient/Makefile.PL: No such directory ‘/opt/mqm’
Compilation failed in require at ./Makefile.PL line 14.
# Looks like your test died before it could output anything.

This seem as it needs /opt/mqm directory to install to and its not creating it by itself. But this was foolish assumption, as most applications create the required directories itself when installing, but still there wasn’t any clear error message. Then somehow I came to know about the client and I installed the MQSeriesClient. Installing MQSeriesClient requires MQSeriesRuntime as well. This created two directories:

  • /opt/mqm and
  • /var/mqm

So, that means Perl Extension was unable to find the client, but instead it was complaining about the directory. Well I moved forward and tried again installing MQSeries Perl Extension. But what? again error?

> perl Makefile.PL
Checking if your kit is complete…
Looks good
ERROR from evaluation of /home/jawaid/MQSeries-1.29/MQClient/Makefile.PL: Missing inc or include directory in /opt/mqm
Compilation failed in require at ./Makefile.PL line 14.
# Looks like your test died before it could output anything.

dahhh!! Now its complaining about another directory inc or include in /opt/mqm. That means it requires something else as well. The name of the directory i.e include, sparked in my mind that it might requires some kind of SDK or something. Then I checked the RPMs came with WMQ. I found MQSeriesSDK. hmmm so I thought lets try installing this RPM and try my luck again with installing Perl Extension. So I installed MQSeriesSDK and then MQSeries Perl Extension. woala!! this time it generated the make file without any errors :)

> perl Makefile.PL
Checking if your kit is complete…
Looks good
Writing Makefile for MQClient::MQSeries
Writing Makefile for MQSeries::Message::DeadLetter
Writing Makefile for MQSeries::Message::PCF
Warning: Guessing NAME [MQSeries-OAM] from current directory name.
No libmqm server library found, MQServer disabled
Support for MQServer is disabled on this platform.
Warning: Guessing NAME [MQServer] from current directory name.
Writing Makefile for MQSeries

But hold your breath for more. You can expect anything now after happening all this. Anyway, I ran make successfully then ran make test… what?? it failed??  :’(

aaahhh!! now what?? never mind!! I just ran make install… guess what? no, you are wrong :) no errors this time, it got installed, even after failing the make test :)

To verify i tried to run the example perl script in examples directory of MQSeries Perl Extension to put message in the queue, and i got an error from the MQSeries library that it didn’t find the queue, obviously there were no queues at the moment, that means Perl module is installed correctly…whew!!

That means installing the run time and client are not enough. You need to install the WMQ SDK as well to install the MQSeries Perl Extension.

Since I wanted to play with the WebSphere MQ, so when I failed to install the Perl Extension first time, I decided to install the server first on another machine. Somehow I managed to install the server. Then I tried to install the MQSeries Perl Extension, but to no avail. Even after installing the Client. Then I moved to another machine and did the whole this thing from scratch, and at last it worked :)

Enable X Session over SSH

Posted by: Jawaid on: 5 August 2009

Sometimes there is a need to use the graphical X session on Linux machines but you cannot do so, since you don’t have access to the machine, you can just SSH it. But you can forward your X session over SSH. To do this use the -X option. If you are using putty then you can set the option like this. Go to:

Connection -> SSH -> X11 -> “Enable X11 forwarding”

This will enable X session over SSH on putty.

Enjoy the GUI ;)

How to setup PHP development environment in Eclipse?

Posted by: Jawaid on: 24 July 2009

As I am currently working on Joomla (http://www.joomla.org/) a CMS built in PHP, I came across a very nice tutorial about how to setup your development environment if you want to work on Joomla. Although the tutorial is specific to Joomla, PHP, and Eclipse, but in general it is a very good tutorial and one can learn how to setup a development environment for any project irrespective of technology used. Especially novice programmers will learn a lot from it.

Author first explained how to install and configure XAMPP, then configure PHP and XDebug to debug the PHP applications. Then author explained how to install Eclipse, setup your workspace, configure it for debugging. Then author created a test project and ran it in debug mode. Then in the end author explained how to install and configure subclipse (Eclipse SVN plug-in) and how to import a project from SVN repository.

This is a very nice tutorial in general and specifically for those who work in Eclipse and PHP. Wanna read it? go ahead: http://docs.joomla.org/Setting_up_your_workstation_for_Joomla!_development

MySQL Query Cache

Posted by: Jawaid on: 26 June 2009

MySQL query cache is good to cache select queries and their results and improve some performance of your database applications. So I thought I should write a quick tutorial to quickly set up the query cache without going into the details. So here what you have to do to enable query cache on MySQL.

If you want to enable query cache without restarting the MySQL server then just run the following command on MySQL prompt/client:

set global query_cache_size=67108864;


This will set MySQL query cache size to around 64MB and also enable the query cache. You can set it to any value you desire. You can then check the status later by running following commands on MySQL prompt/client:

SHOW VARIABLES LIKE ‘%query_cache%’;

SHOW STATUS LIKE ‘%qcache%’;


These commands will show some useful information about the query cache like if query cache is enabled, how much memory is being used, how many queries are currently in cache, cache hit rate etc.

This is really a quick way to enable query cache. For details see MySQL documentation http://dev.mysql.com/tech-resources/articles/mysql-query-cache.html

CVS account change in Eclipse

Posted by: Jawaid on: 26 June 2009

We were setting up new development environment for our team using eclipse and checked out the code from CVS. At the end we faced an issue when we tested how other developers will change the CVS account to their own one. Eclipse was not allowing us to change the CVS account. Then I found that we have to change the account in CVS meta files. The command I used to replace the account was :

find . -regex .*CVS/Root -print0 | xargs -0 perl -p -i.orig -e “s/olduser/newuser/;”

This replaced the CVS user name in all CVS meta files in the whole project hierarchy :)

Multiple MySQL on single host

Posted by: Jawaid on: 29 May 2009

Sometimes we need to run multiple MySQL servers on single machine. That is mostly required in testing environments to test different aspects with different configurations. In this way one can test server without affecting others. So, if you want to run multiple MySQL you can use MySQL Sandbox which eases the whole process of installing and configuring the server. Here how will you do it.

First of all you need to install MySQL Sandbox. You can download it from https://launchpad.net/mysql-sandbox.

Then you need tar balls of MySQL server. You can download it from MySQL site.

After installing MySQL Sandbox you can run following script to install MySQL.

make_sandbox /path/to/mysql-X.X.XX-osinfo.tar.gz

This script will tell you some information like port, user name, and password which you can use to login to MySQL after installation. After confirmation it will install and run MySQL. That’s it! You are up and running.

If you want to install another MySQL you can just run the following command.

make_sandbox /path/to/mysql-X.X.XX-osinfo.tar.gz –check_port

The –check_port option checks the first available port so it can install and run on that port. By default it will use the MySQL version as port. For example if you have MySQL version 4.1.20 it will run MySQL on port 4120. And if it is not available then it will try 4121.

MySQL Sandbox provides other useful scripts to manage the server. So installing and running multiple MySQL, even different versions, is that easy :)

You can find the complete documentation at http://forge.mysql.com/wiki/MySQL_Sandbox#Single_server_sandbox.

Why code bad?

Posted by: Jawaid on: 7 May 2009

I was reading the book Clean Code – A Handbook of Agile Software Craftsmanship, Rober C. Martin Series. A section in chapter one caught my attention and remind me of code and reasons that I got for writing bad code and designing bad solution. Now I think this is a good argument against it which I am quoting here from the book.

“Have you ever waded through a mess so grave that it took weeks to do what should have taken hours? Have you seen what should have been a one-line change, made instead in hundreds of different modules? These symptoms are all too common. Why does this happen to code? Why does good code rot so quickly into bad code? We have lots of explanations for it. We complain that the requirements changed in ways that thwart the original design. We bemoan the schedules that were too tight to do things right.
We blather about stupid managers and intolerant customers and useless marketing types and telephone sanitizers. But the fault, dear Dilbert, is not in our stars, but in ourselves. We are unprofessional.
This may be a bitter pill to swallow. How could this mess be our fault? What about the requirements? What about the schedule? What about the stupid managers and the useless marketing types? Don’t they bear some of the blame?
No. The managers and marketers look to us for the information they need to make promises and commitments; and even when they don’t look to us, we should not be shy about telling them what we think. The users look to us to validate the way the requirements
will fit into the system. The project managers look to us to help work out the schedule. We are deeply complicit in the planning of the project and share a great deal of the responsibility for any failures; especially if those failures have to do with bad code! “But wait!” you say. “If I don’t do what my manager says, I’ll be fired.” Probably not. Most managers want the truth, even when they don’t act like it. Most managers want good code, even when they are obsessing about the schedule. They may defend the schedule and requirements with passion; but that’s their job. It’s your job to defend the code with equal passion.
To drive this point home, what if you were a doctor and had a patient who demanded that you stop all the silly and-washing in preparation for surgery because it was taking too much time?2 Clearly the patient is the boss; and yet the doctor should absolutely refuse to comply. Why? Because the doctor knows more than the patient about the risks of disease and infection. It would be unprofessional (never mind criminal) for the doctor to comply with the patient.
So too it is unprofessional for programmers to bend to the will of managers who don’t understand the risks of making messes.”

Breaking problem into code

Posted by: Jawaid on: 22 April 2009

Let us consider an example. If you have two boxes say BoxA and BoxB, and there are few balls of different colors, let’s say 5 balls (red, blue, green, yellow, and white) in BoxA, and you want to move one ball, say red ball from BoxA to BoxB. What will be the steps? If you can make a flow chart of it then its good, but if you find it difficult to make a flow chart of it then you need to do some hard work to become a programmer.

I asked this to someone and guess how he solved it. Here is his solution. Take out all balls from BoxA, then pick the red ball, put it in BoxB, and then put all remaining balls back in BoxA.

Fine! it worked. But why would you take out all balls if you can only take out red ball and move it to next box?

Let’s move this to programming side. In the above mentioned scenario we will have two database tables, boxes, and balls. boxes will have boxid as PK, name, and other details. Keep it simple so we don’t get lost in other details. balls table has ballid as PK, name, boxid as FK, and other details. boxes table has two records with 1 and BoxA as its boxid and name. balls table will have 5 records with id between 1 to 5 and red, blue, green, yellow, and white as their names, and all balls will have 1 in boxid field which is FK to boxes table.

Now if we adopt the first solution then it will run following queries (these are pseudo queries not actual SQL queries):

– select all balls where boxid=1 (so we can have a list of all balls before deleting them from database)
– delete from balls where boxid=1
– insert into balls values ballid=1, name=red ball, boxid=2
– insert into balls values
(ballid=2, name=blue ball, boxid=1)
(ballid=3, name=green ball, boxid=1)
(ballid=4, name=yellow ball, boxid=1)
(ballid=5, name=white ball, boxid=1)

Or even worse if we use multiple insert queries. It will run from 4 to 7 queries.

Now let’s see what happens if we just perform operation on the red ball and don’t touch other balls.

– update balls set boxid=2 where ballid=1; /* ball with id 1 is the red ball */

Wow, just one query and we’re done! We saved 3 to 6 queries. Imagine this scenario for a high traffic website or any other application, we can improve the performance with a big difference by just implementing correct logic to solve a problem.

J’s Blog Feeds

J’s Archives

Blog Stats

  • 630 hits

J’s Calendar

November 2009
M T W T F S S
« Oct    
 1
2345678
9101112131415
16171819202122
23242526272829
30  

  • None
  • Jawaid: Yes sure, and also why did it failed on make test, but successfully ran make install.
  • Andy Piper: Thanks for posting this. So it looks like the Perl extension (which is a 3rd party module, by the way) needs to specify the dependencies in its docume
  • m sami khan: Hello Jawaid I really admire your efforts and help in the response of your hard work and research. Your blog helps alot for not only amateur people

J’s Categories

J’s Pages

Top Posts

  • None

Top Clicks

  • None

J’s Blog Feeds Email Subscription

Enter your email address:

Delivered by FeedBurner

J’s Blog Feeds Email Subscription

J’s Feed Count

Twitter Updates

J's del.icio.us