Amazon

Sunday, November 28, 2010

MQ Manager Configuration Script

1.Create a queue Manager
crtmqm MQIPH

2.Start the Queue Manager
strmqm MQIPH

3.Start the MQ browser to create the queues
runmqsc MQIPH

4. Define Dead letter queue
DEFINE QLOCAL('Q.MQIPH.DLQ') DEFPSIST(YES)
ALTER QMGR DEADQ('Q.MQIPH.DLQ') 

5. Define Server Connection Channel
DEFINE CHANNEL(MQIPH.SRV.CHANNEL) CHLTYPE(SVRCONN) TRPTYPE(TCP)

6. Define q local
DEFINE QLOCAL('Q.MQIPH2_TO_MQIPH') DEFPSIST(YES)

7. Define Xmitq
DEFINE QLOCAL('MQIPH.XMITQ') +
 USAGE(XMITQ)

8. Define q Remote
DEFINE QREMOTE('RQ.MQIPH_TO_MQIPH2') +
    RNAME('Q.MQIPH_TO_MQIPH2') +
    RQMNAME('MQIPH2') XMITQ('MQIPH.XMITQ') DEFPSIST(YES) 

9. Define sender channel
DEFINE CHL ('MQIPH_TO_MQIPH2') +
 CHLTYPE(SDR) TRPTYPE(TCP) +
 CONNAME('172.16.2.24(1414)') +
 XMITQ('MQIPH.XMITQ') +
 DISCINT (0)

10. Define receiver channel
DEFINE CHL ('MQIPH2_TO_MQIPH') +
 CHLTYPE(RCVR) TRPTYPE(TCP)

11.Create a queue Manager
crtmqm MQIPH2

12.Start the Queue Manager
strmqm MQIPH2

13.Start the MQ browser to create the queues
runmqsc MQIPH2

14. Define Server Connection Channel
DEFINE CHANNEL(MQIPH2.SRV.CHANNEL) CHLTYPE(SVRCONN) TRPTYPE(TCP)

15. Define Dead letter queue
DEFINE QLOCAL('Q.MQIPH2.DLQ') DEFPSIST(YES)
ALTER QMGR DEADQ('Q.MQIPH2.DLQ')

16. Define q local
DEFINE QLOCAL('Q.MQIPH_TO_MQIPH2') DEFPSIST(YES)

17. Define xmitq local
DEFINE QLOCAL('MQIPH2.XMITQ') +
USAGE(XMITQ)

18. Define q Remote
DEFINE QREMOTE('RQ.MQIPH2_TO_MQIPH') +
    RNAME('Q.MQIPH2_TO_MQIPH') +
    RQMNAME('MQIPH') XMITQ('MQIPH2.XMITQ') DEFPSIST(YES)


19. Define sender channel
DEFINE CHL ('MQIPH2_TO_MQIPH') +
 CHLTYPE(SDR) TRPTYPE(TCP) +
 CONNAME('172.16.2.24(1415)') +
 XMITQ('MQIPH2.XMITQ') +
 DISCINT (0)

20. Define Receiver channel
DEFINE CHL ('MQIPH_TO_MQIPH2') +
 CHLTYPE(RCVR) TRPTYPE(TCP)

21.Start the Senders Listener Port on 1414
runmqlsr -t tcp -m MQIPH2 -p 1414 &

22.Start the Senders Listener Port on 1415
runmqlsr -t tcp -m MQIPH -p 1415 &

23.Start the Sender Channel
START CHANNEL (MQIPH_TO_MQIPH2)

24.Start the Channel
START CHANNEL (MQIPH2_TO_MQIPH)

Saturday, November 20, 2010

Calling Unix Shell Script from Java Program

Requirement : Calling a Unix Shell Script from Java program and returning result to the Java program from Unix Shell Script.

UNIX Code : 

1 #!/bin/bash
3 function myscript(){
4 set a = 10
5 echo ID from JSP is $id
6 echo 'i m here babe' >> /usr12/SPHI/SIR03174/sanjeev/a.txt
7 ls -lrt
8 return 122
9 }
10
11 myscript

Line 1: Most important Line the shell script. If this is missed Java module won't be able to invoke the Shell Script.
Lin 3: Name of the function, which need to be invoked by shell script at last (see line 11).
Line 4: Create a variable.
Line 5: The env variable id (expressed as $id) will be set in Java module and sent to this function while calling shell script.
Line 11: calling the Unix Function at the end of script, otherwise the code will not be invoked.

JSP Code : This will call the above Unix Shell script, pass a parameter to shell script and read the result from Unix script.


1   <%--
2       Document   : proc.jsp
3       Created on : Nov 1, 2010, 2:48:14 PM
4       Author     : sanjeev pandey
5   --%>
6
7   <%@page contentType="text/html" pageEncoding="UTF-8"%>
8
9   <%@page import="java.io.BufferedReader"%>
10  <%@page import="java.io.File"%>
11  <%@page import="java.io.InputStream"%>
12  <%@page import="java.io.InputStreamReader"%>
13
14
15  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
16     "http://www.w3.org/TR/html4/loose.dtd">
17
18  <html>
19      <head>
20          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
21          <title>JSP Page</title>
22      </head>
23      <body>
24          <h1>Hello World!</h1>
25           <%
26   String [] env = {"id=pheonix1"};
27              Runtime rt = Runtime.getRuntime();
28              out.println("Runtime : "+rt);
29
30              Process p = rt.exec("/usr/scpt.sh", env);
31              out.println("<br><br>Process : "+p);                                        
32
33              InputStream is =  p.getInputStream();
34              out.println("<br><br>InputStream : "+is);
35
36              BufferedReader br = new BufferedReader(new InputStreamReader(is));
37              out.println("<br><br>BufferedReader : "+br);
38                                                                                            
39              String line = "";
40              out.println("<br><br>line is space : "+line);
41                                                                                            
42              while(line != null) {
43                  line = br.readLine();
44                  out.println("<br><br>Reading inputstream : "+ line);
45              }
46          %>
47      </body>
48  </html>                                                                                          

Line 26: Creating String Variable to be passed to shell script. In shell script its treated as environment variable.
Line 30: Passing the Variable embedded in 'env' to shell script before executing it from java.
Line 33: Getting the inputstream, created after execution of the Unix script. This input stream contains all the things which are printed on unix when the shell script is executed.
Line 42-45: Printing the unix output on JSP.


Amazon Best Sellors

TOGAF 9.2 - STUDY [ The Open Group Architecture Framework ] - Chap 01 - Introduction

100 Feet View of TOGAF  What is Enterprise? Collection of Organization that has common set of Goals. Enterprise has People - organized by co...