Featured Post

Hi Guys, Today I would like to share information on WebSphere MQ concepts ,I am currently working on JMS and Seo integration which is another wing in SEO domain . so I extensively worked on this sharing information with you guys . In order to understand this you should have sound knowledge on JMS concepts like Producer and consumer and also sound knowledge on MQ Series IBM product . I am not going to give you theoretical concept as we have many books available . Directly I am providing code which is working in Websphere 7.0 please let me know comments and suggestions Message Producer ----------------- final Hashtable env = new Hashtable(); MQEnvironment.hostname = "your vhost name"; MQEnvironment.port = port; MQEnvironment.channel = "your channel name"; if(environment.trim().equalsIgnoreCase("DEV")){ MQEnvironment.hostname = "you host name"; MQEnvironment.port = port; MQEnvironment.channel = "channel name"; } MQQueueManager _qMgr=null; try{ _qMgr = new MQQueueManager(""); int openOptions = 17; MQQueue eventQueue = _qMgr.accessQueue("QUEUE", openOptions, null, null, null); MQMessage m = new MQMessage(); m.format = "MQSTR "; m.characterSet = 500; m.encoding = 785; m.writeString(message); eventQueue.put(m, new MQPutMessageOptions()); System.out.println("Dropped..!"+message+" In "+environment); eventQueue.close(); _qMgr.disconnect(); } catch (Exception e) { e.printStackTrace(); System.exit(2); } And consumer looks like this , consumer should be deployed in WAS so here you need InitialContext object Consumer -------- Step 1: Initialize properties as follows private static void initializeProperties() { if(properties == null) { properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"); } } Initialize Context as shown in below code snippet step 2: if(ctx == null) { try { ctx = new InitialContext(properties); } catch(NamingException e) { throw e; } } look up for the Context Object step3: obj = ctx.lookup(jndiName); Step 4: define your JNDI name in WAS admin console and using JNDI lookup you can get the object as follows Object obj = jndiLookup(Constants.MQ_FILEMON_QUEUE_FACTORY); return (ConnectionFactory) obj; } get ConnectionFactory as shown below step 5: MQQueue queue = new MQQueue(Constants.MQ_FILEMON_QUEUE); queue .setTargetClient(JMSC.MQJMS_CLIENT_NONJMS_MQ); queue .setCCSID(Constants.MQ_CHAR_ENCODE_EBCDIC); step 6: from ConnectionFactory get connection object from Connection get Session Object from Session you create Consumer as shown below if(connectionFactory != null) { jmsConnection = connectionFactory.createConnection(); if(jmsConnection != null) { session = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); if(session != null) { if(fileMonitorQueue != null) { consumer = session.createConsumer(fileMonitorQueue); jmsConnection.start(); } } } } Thanks Sitaram Sarma and Sitaram.pv

Enter you DOB ,Time and Place

SEO Schemes

Comments