Friday, February 8, 2013

RFH With IBM MQ - EMULATING JMS in .NET

Afer some problems, this worked for me:

MQMessage definitioN:

MQMessage strXMLMessage = new MQMessage();

strXMLMessage.CharacterSet = 1208;


strXMLMessage.Format = "MQHRF2";

Class:

public static MQMessage WriteHeader(MQMessage mqMsg, string fileName, MQQueue queue)

var encoding = new System.Text.UTF8Encoding();

// OLD HARD CODED STRINGS
//var mcdHeader = @"jms_text";
//var jmsHeader = @"queue:///APPS/OOT/REQUEST12970426443072";
//var usrHeader = @"1122TestReceiver";

// NEW DYNAMIC CONFIG LOADED STRINGS
var mcdHeader = @"RFH:DATA";
var jmsHeader = @"queue://"+queue.Name.ToString().TrimEnd()+""+ (((long)System.DateTime.Now.Ticks) - 621355968000000000)/10000 +"2";
var usrHeader = @""+fileName+"";



while (encoding.GetByteCount(jmsHeader) % 4 != 0)
{
jmsHeader = jmsHeader + " "; // add space here for tracking total length (don't actually do anything with this one) 
}

while (encoding.GetByteCount(mcdHeader) % 4 != 0)
{
mcdHeader = mcdHeader + " "; // add space here for tracking total length (don't actually do anything with this one) 
}

// add space here for tracking total length (don't actually do anything with this one)
while (encoding.GetByteCount(usrHeader) % 4 != 0)
{
usrHeader = usrHeader + " "; 

}

var rfhHeader = mcdHeader + jmsHeader + usrHeader;

// last item in name value section gets the extra spaces
var rfhHeaderLen = encoding.GetByteCount(rfhHeader);

Int32 iStrucLength = IBM.XMS.MQC.MQRFH_STRUC_LENGTH_FIXED_2 + rfhHeaderLen + 12 ; // 3 header lengths * 4 bytes

// RFH HEADER 
mqMsg.Format = IBM.XMS.MQC.MQFMT_RF_HEADER_2; // Msg Format //comentar si tal
mqMsg.WriteBytes(IBM.XMS.MQC.MQRFH_STRUC_ID); // Structure identifier 
mqMsg.WriteInt4(IBM.XMS.MQC.MQRFH_VERSION_2); // Structure version number
mqMsg.WriteInt4(iStrucLength); // Total length of MQRFH2 including NameValueData
mqMsg.WriteInt4(IBM.XMS.MQC.MQENC_NATIVE); // Numeric encoding of data that follows NameValueData 
mqMsg.WriteInt4(1208); // Character set identifier of data that follows NameValueData
mqMsg.WriteBytes(IBM.XMS.MQC.MQFMT_NONE); // Format name of data that follows NameValueData
mqMsg.WriteInt4(IBM.XMS.MQC.MQRFH_NO_FLAGS); // Flags //descomentar si cual
mqMsg.WriteInt4(1208); // Character set identifier of NameValueData, 1208 = UTF-8

// Optional NameValueData folders and their content must occur in the sequence (length, data)

mqMsg.WriteInt4(encoding.GetByteCount(mcdHeader));
mqMsg.WriteBytes(mcdHeader);

mqMsg.WriteInt4(encoding.GetByteCount(jmsHeader));
mqMsg.WriteBytes(jmsHeader);

mqMsg.WriteInt4(encoding.GetByteCount(usrHeader));
mqMsg.WriteBytes(usrHeader);

return mqMsg;
}

Thursday, December 18, 2008

IHS or Apache 2 Performance Tuning

Ok, How to improve Apache performance, i´ll show you some tips:

1- Use mod_gzip to compress html, text, css... here is a example:

DeflateCompressionLevel 9

AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE application/x-httpd-eruby
AddOutputFilterByType DEFLATE text/html


2 - Enable Apache cache, example:

LoadModule disk_cache_module modules/mod_disk_cache.so

CacheRoot /www/cache

## 1 Gb ##
CacheSize 100000000

##6 Mb ##
CacheMaxFileSize 6400000

## 640 bytes ###
CacheMinFileSize 640

## Expires in 1 hour ###
CacheDefaultExpire 3600
## Things to do cache ##
CacheEnable disk /

CacheDirLevels 5
CacheDirLength 3



3 - Combination of mod_headers and mod_expires, example:

LoadModule headers_module modules/mod_headers.so

Header set Cache-Control "public"

### Enable mod Expire ###

LoadModule expires_module modules/mod_expires.so

# turn on the module for this directory
ExpiresActive on
Header set Cache-Control "public"

# cache common graphics for 3 days
ExpiresByType image/jpg "access plus 3 days"
ExpiresByType image/gif "access plus 3 days"
ExpiresByType image/jpeg "access plus 3 days"
#ExpiresByType application/pdf "access plus 3 days"
ExpiresByType application/x-javascript "access plus 3 days"
ExpiresByType application/x-shockwave-flash "access plus 3 days"
ExpiresByType video/x-flv "access plus 3 days"
ExpiresByType text/plain "access plus 3 days"
ExpiresByType text/javascript "access plus 3 days"
ExpiresByType application/javascript "access plus 3 days"

# cache CSS for 3 days
ExpiresByType text/css "access plus 3 days"

# set the default to 24 hours
ExpiresDefault "access plus 3 seconds"



All this things will reduce in 30%-40% you network traffic and improve the speed.
In my opinion the best module is mod_gzip, cause no impact on the applications, all almost all web browsers support it.
Good Luck

Wednesday, December 10, 2008

Log4j and WAS 6.1 Problems

¿Problems with log4j after updating your WAS?
If your applications writes to a log file defined in log4j.properties and after install any IBM fix pack those applications stop to write in this log and writes in system.out just follow the next steps:
1- create a file called: commons-logging.properties and place this into it:
priority=100
org.apache.commons.logging.LogFactory=
org.apache.commons.logging.impl.LogFactoryImpl
org.apache.commons.logging.Log=
org.apache.commons.logging.impl.Log4JLogger
2- Copy this file in this directory: [profile_dir]/properties/
3- Stop and Start your servers and that´s it¡¡¡