跳到主要內容

MQ PCF API簡介

可以透過該API管理QMGR

MQAgent.java---
package cgw.mq.admin;

import cgw.mq.bean.MQManageBean;
import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQException;
import com.ibm.mq.pcf.PCFMessageAgent;

public class MQAgent {
private PCFMessageAgent agent;

public MQAgent(MQManageBean bean ,int ccsid){
//MQEnvironment.CCSID = ccsid;
try {
PCFMessageAgent agent = new PCFMessageAgent(bean.getMqm_ip(),bean.getMqm_port(),bean.getAdmin_channel());
} catch (MQException e) {
e.printStackTrace();
}
agent.setCharacterSet(ccsid);
}
public PCFMessageAgent getAgent() {
return agent;
}
public void close() throws MQException{
agent.disconnect();
}
}

MQManageBean.java---
package cgw.mq.bean;

public class MQManageBean {
private String mqm_ip;
private int mqm_port;
private String admin_channel;

public String getAdmin_channel() {
return admin_channel;
}
public void setAdmin_channel(String admin_channel) {
this.admin_channel = admin_channel;
}
public String getMqm_ip() {
return mqm_ip;
}
public void setMqm_ip(String mqm_ip) {
this.mqm_ip = mqm_ip;
}
public int getMqm_port() {
return mqm_port;
}
public void setMqm_port(int mqm_port) {
this.mqm_port = mqm_port;
}
}

MQChannel.java---
package cgw.mq.admin;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import cgw.mq.bean.MQChannelBean;
import cgw.mq.bean.MQManageBean;
import com.ibm.mq.MQException;
import com.ibm.mq.pcf.CMQC;
import com.ibm.mq.pcf.CMQCFC;
import com.ibm.mq.pcf.CMQXC;
import com.ibm.mq.pcf.PCFException;
import com.ibm.mq.pcf.PCFMessage;
import com.ibm.mq.pcf.PCFMessageAgent;

public class MQChannel {

private PCFMessageAgent agent;

private int[] attrs = { CMQCFC.MQCACH_CHANNEL_NAME,
CMQCFC.MQCACH_CONNECTION_NAME, CMQCFC.MQIACH_MSGS,
CMQCFC.MQCACH_LAST_MSG_DATE, CMQCFC.MQCACH_LAST_MSG_TIME,
CMQCFC.MQIACH_CHANNEL_STATUS, CMQCFC.MQIACH_CHANNEL_TYPE };

public static void main(String args[]) throws MQException {
MQManageBean bean = new MQManageBean();
bean.setMqm_ip("192.168.1.2");
bean.setMqm_port(1416);
bean.setAdmin_channel("SYSTEM.DEF.SVRCONN");
MQAgent agent = new MQAgent(bean, 950);
MQChannel mqc = new MQChannel();
// PCFMessageAgent agent = new PCFMessageAgent("testPcf");
mqc.setAgent(agent.getAgent());
try {
//mqc.startChannelListener();
MQChannelBean channelBean = new MQChannelBean();
channelBean.setChannelName("go");
channelBean.setChannelType(CMQXC.MQCHT_SVRCONN);
mqc.createChannel(channelBean);
} catch (PCFException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public List chkChannel(String targetChannel) {
ArrayList beanList = new ArrayList();
try {
PCFMessage request = new PCFMessage(
CMQCFC.MQCMD_INQUIRE_CHANNEL_STATUS);
request.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, targetChannel);
request.addParameter(CMQCFC.MQIACH_CHANNEL_INSTANCE_TYPE,
CMQC.MQOT_CURRENT_CHANNEL);
request.addParameter(CMQCFC.MQIACH_CHANNEL_INSTANCE_ATTRS, attrs);
PCFMessage[] pcf_resp = getAgent().send(request);
for (int i = 0; i < pcf_resp.length; i++){
MQChannelBean bean = new MQChannelBean();
bean.setChannelName(pcf_resp[i]
.getStringParameterValue(CMQCFC.MQCACH_CHANNEL_NAME));
bean.setChannelType(pcf_resp[i]
.getIntParameterValue(CMQCFC.MQIACH_CHANNEL_TYPE));
bean
.setConnectionName(pcf_resp[i]
.getStringParameterValue(CMQCFC.MQCACH_CONNECTION_NAME));
bean.setMsgCount(pcf_resp[i]
.getIntParameterValue(CMQCFC.MQIACH_MSGS));
bean.setLastMsgDate(pcf_resp[i]
.getStringParameterValue(CMQCFC.MQCACH_LAST_MSG_DATE));
bean.setLastMsgTime(pcf_resp[i]
.getStringParameterValue(CMQCFC.MQCACH_LAST_MSG_TIME));
bean.setStatus(pcf_resp[i]
.getIntParameterValue(CMQCFC.MQIACH_CHANNEL_STATUS));
beanList.add(bean);
}
} catch (PCFException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return beanList;
}

public void startChannelListener() throws PCFException, MQException, IOException{
PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_START_CHANNEL_LISTENER);
getAgent().send(channel_msg);
}
public void stopChannel(MQChannelBean bean) throws PCFException,
MQException, IOException {
PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_STOP_CHANNEL);
channel_msg.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, bean
.getChannelName());
channel_msg.addParameter(CMQCFC.MQCACH_CONNECTION_NAME, bean
.getConnectionName());
getAgent().send(channel_msg);
}

public void startChannel(MQChannelBean bean) throws PCFException,
MQException, IOException {
PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_START_CHANNEL);
channel_msg.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, bean
.getChannelName());
channel_msg.addParameter(CMQCFC.MQCACH_CONNECTION_NAME, bean
.getConnectionName());
getAgent().send(channel_msg);
}

public void createChannel(MQChannelBean bean) throws PCFException,
MQException, IOException {
PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_CREATE_CHANNEL);
channel_msg.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, bean
.getChannelName());
channel_msg.addParameter(CMQCFC.MQIACH_CHANNEL_TYPE, bean
.getChannelType());
getAgent().send(channel_msg);
}

public PCFMessageAgent getAgent() {
return agent;
}

public void setAgent(PCFMessageAgent agent) {
this.agent = agent;
}
}

MQQueue.java---
package cgw.mq.admin;

import java.io.IOException;
import cgw.mq.bean.MQManageBean;
import com.ibm.mq.MQException;
import com.ibm.mq.pcf.CMQC;
import com.ibm.mq.pcf.CMQCFC;
import com.ibm.mq.pcf.PCFException;
import com.ibm.mq.pcf.PCFMessage;
import com.ibm.mq.pcf.PCFMessageAgent;

public class MQQueue {
private String targetQueue;
private int depth;
private PCFMessage pcf_req;
private PCFMessageAgent agent;
private int[] attrs = { CMQC.MQCA_Q_NAME, CMQC.MQIA_CURRENT_Q_DEPTH };
public static void main(String[] arg){
MQManageBean bean = new MQManageBean();
bean.setMqm_ip("192.168.1.1");
bean.setMqm_port(1414);
bean.setAdmin_channel("SYSTEM.DEF.SVRCONN");
MQAgent agent = new MQAgent(bean,950);
MQQueue mqq = new MQQueue();
mqq.setTargetQueue("TEST");
mqq.setAgent(agent.getAgent());
mqq.init();
/*
try {
//mqq.createQueue();
//mqq.removeQueue();
//mqq.clearQueue();
} catch (PCFException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
*/
mqq.chkQueueDepth();
System.out.println(mqq.getDepth());
}
public void init(){
pcf_req = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q);
pcf_req.addParameter(CMQC.MQCA_Q_NAME, getTargetQueue());
pcf_req.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_LOCAL);
pcf_req.addParameter(CMQCFC.MQIACF_Q_ATTRS, attrs);
}
public void chkQueueDepth(){
try {
PCFMessage[] pcf_resp = getAgent().send(getPcf_req());
for(int i = 0;i
String tmp = pcf_resp[i].getStringParameterValue(CMQC.MQCA_Q_NAME).trim();
if(getTargetQueue().equals(tmp)){
setDepth(pcf_resp[i].getIntParameterValue(CMQC.MQIA_CURRENT_Q_DEPTH));
}else{
setDepth(-1);
}
}
} catch (PCFException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void createQueue() throws PCFException, MQException, IOException{
PCFMessage queue_msg = new PCFMessage(CMQCFC.MQCMD_CREATE_Q);
queue_msg.addParameter(CMQC.MQCA_Q_NAME, getTargetQueue());
queue_msg.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_LOCAL);
getAgent().send(queue_msg);
}
public void removeQueue() throws PCFException, MQException, IOException{
PCFMessage queue_msg = new PCFMessage(CMQCFC.MQCMD_DELETE_Q);
queue_msg.addParameter(CMQC.MQCA_Q_NAME, getTargetQueue());
queue_msg.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_LOCAL);
getAgent().send(queue_msg);
}
public void clearQueue() throws PCFException, MQException, IOException{
PCFMessage queue_msg = new PCFMessage(CMQCFC.MQCMD_CLEAR_Q);
queue_msg.addParameter(CMQC.MQCA_Q_NAME, getTargetQueue());
//queue_msg.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_LOCAL);
getAgent().send(queue_msg);
}
public String getTargetQueue() {
return targetQueue;
}

public void setTargetQueue(String targetQueue) {
this.targetQueue = targetQueue;
}

public int getDepth() {
return depth;
}

public void setDepth(int depth) {
this.depth = depth;
}

public PCFMessage getPcf_req() {
return pcf_req;
}

public void setPcf_req(PCFMessage pcf_req) {
this.pcf_req = pcf_req;
}

public PCFMessageAgent getAgent() {
return agent;
}

public void setAgent(PCFMessageAgent agent) {
this.agent = agent;
}
}




package cgw.mq.admin;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import cgw.mq.bean.MQChannelBean;
import cgw.mq.bean.MQManageBean;
import com.ibm.mq.MQException;
import com.ibm.mq.pcf.CMQC;
import com.ibm.mq.pcf.CMQCFC;
import com.ibm.mq.pcf.CMQXC;
import com.ibm.mq.pcf.PCFException;
import com.ibm.mq.pcf.PCFMessage;
import com.ibm.mq.pcf.PCFMessageAgent;

public class MQChannel {

private PCFMessageAgent agent;

private int[] attrs = { CMQCFC.MQCACH_CHANNEL_NAME,
CMQCFC.MQCACH_CONNECTION_NAME, CMQCFC.MQIACH_MSGS,
CMQCFC.MQCACH_LAST_MSG_DATE, CMQCFC.MQCACH_LAST_MSG_TIME,
CMQCFC.MQIACH_CHANNEL_STATUS, CMQCFC.MQIACH_CHANNEL_TYPE };

public static void main(String args[]) throws MQException {
MQManageBean bean = new MQManageBean();
bean.setMqm_ip("192.168.1.2");
bean.setMqm_port(1416);
bean.setAdmin_channel("SYSTEM.DEF.SVRCONN");
MQAgent agent = new MQAgent(bean, 950);
MQChannel mqc = new MQChannel();
// PCFMessageAgent agent = new PCFMessageAgent("testPcf");
mqc.setAgent(agent.getAgent());
try {
//mqc.startChannelListener();
MQChannelBean channelBean = new MQChannelBean();
channelBean.setChannelName("go");
channelBean.setChannelType(CMQXC.MQCHT_SVRCONN);
mqc.createChannel(channelBean);
} catch (PCFException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public List chkChannel(String targetChannel) {
ArrayList beanList = new ArrayList();
try {
PCFMessage request = new PCFMessage(
CMQCFC.MQCMD_INQUIRE_CHANNEL_STATUS);
request.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, targetChannel);
request.addParameter(CMQCFC.MQIACH_CHANNEL_INSTANCE_TYPE,
CMQC.MQOT_CURRENT_CHANNEL);
request.addParameter(CMQCFC.MQIACH_CHANNEL_INSTANCE_ATTRS, attrs);
PCFMessage[] pcf_resp = getAgent().send(request);
for (int i = 0; i <>
MQChannelBean bean = new MQChannelBean();
bean.setChannelName(pcf_resp[i]
.getStringParameterValue(CMQCFC.MQCACH_CHANNEL_NAME));
bean.setChannelType(pcf_resp[i]
.getIntParameterValue(CMQCFC.MQIACH_CHANNEL_TYPE));
bean
.setConnectionName(pcf_resp[i]
.getStringParameterValue(CMQCFC.MQCACH_CONNECTION_NAME));
bean.setMsgCount(pcf_resp[i]
.getIntParameterValue(CMQCFC.MQIACH_MSGS));
bean.setLastMsgDate(pcf_resp[i]
.getStringParameterValue(CMQCFC.MQCACH_LAST_MSG_DATE));
bean.setLastMsgTime(pcf_resp[i]
.getStringParameterValue(CMQCFC.MQCACH_LAST_MSG_TIME));
bean.setStatus(pcf_resp[i]
.getIntParameterValue(CMQCFC.MQIACH_CHANNEL_STATUS));
beanList.add(bean);
}
} catch (PCFException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return beanList;
}

public void startChannelListener() throws PCFException, MQException, IOException{
PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_START_CHANNEL_LISTENER);
getAgent().send(channel_msg);
}
public void stopChannel(MQChannelBean bean) throws PCFException,
MQException, IOException {
PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_STOP_CHANNEL);
channel_msg.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, bean
.getChannelName());
channel_msg.addParameter(CMQCFC.MQCACH_CONNECTION_NAME, bean
.getConnectionName());
getAgent().send(channel_msg);
}

public void startChannel(MQChannelBean bean) throws PCFException,
MQException, IOException {
PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_START_CHANNEL);
channel_msg.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, bean
.getChannelName());
channel_msg.addParameter(CMQCFC.MQCACH_CONNECTION_NAME, bean
.getConnectionName());
getAgent().send(channel_msg);
}

public void createChannel(MQChannelBean bean) throws PCFException,
MQException, IOException {
PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_CREATE_CHANNEL);
channel_msg.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, bean
.getChannelName());
channel_msg.addParameter(CMQCFC.MQIACH_CHANNEL_TYPE, bean
.getChannelType());
getAgent().send(channel_msg);
}

public PCFMessageAgent getAgent() {
return agent;
}

public void setAgent(PCFMessageAgent agent) {
this.agent = agent;
}
}


留言

這個網誌中的熱門文章

Pentaho kettle取指定目錄下的所有檔案

最近開始玩 BI的東西,而之前專案有使用到Pentaho Open Source這個好物.... Pentaho裡面很多東西,跟 Jasperreport一樣東西很多,我最先接觸到的是kettle ETL的工具,玩了一陣子,開始有空就把它寫下來,以免忘記。 Scan一個目錄下所有檔案,然後塞進去資料庫 1.先拉兩個 Input,一個Get File Names,一個是CSV file input,再拉一個 output 中的 Table output,然後把他連起來。 2.點開 Get File Names,File or directory設定你的指定目錄,Regular Expression則是輸入.*\.*$則是所有檔案,若是CSV則可.*\.torrent$這可以了,可以按一下 Preview rows看看是否正確。

Spring boot v1.5 (六) spring data jpa 基本操作

最近天氣好熱,做甚麼事都覺得很懶,想要寫個spring data jpa也是懶懶的,不過這部分卻也是滿重要的一部分,前一篇介紹 JDBCTemplate ,已經覺得跟以前寫SQL方式有所差異了,JPA帶來的是物件導向的設計面思考,說到JPA不得不提提 ORM ,Object-relational mapping主要想法為簡化及物件導向的設計,讓RDB更貼近Object,在設計上可以更加便利,甚至透過一些設計可以讓Table具有物件導向的特性如繼承等等,以往要使用ORM的框架,都會先以 Hibernate 進行,不過近來慢慢地轉向JPA,主要還是在減少程式碼、增加彈性等等,大體的功能沒有差異很大,所以從Hibernate轉到JPA問題不大,JPA要介紹的東西還滿多的,所以我這裡會再分成三個章節來介紹。 SPRING DATA JPA基本操作 JPQL & Named SQL & Native SQL Cache & DB Design Pattern SPRING DATA JPA更加簡化的程式撰寫,只需要一個 Interface內寫一些查詢 method就可以操作JPA,因為利用 method 組合查詢條件,確實很方便也很容易理解,若是都沒有辦法符合需求當然也可以自己實作一個來用當然沒有問題。 學習目的 :SPRING DATA JPA基本操作。 學習時數 :3.5hr 教學影片: pom.xml 說明 spring-boot-starter-web:配置 Web Project所需的函式庫。 spring-boot-starter-test:配置 unit or mock test 所需的函式庫。 spring-boot-starter-actuator:配置監控spring boot所需的函式庫,後續spring cloud會使用到,所以一開就導入。 spring-boot-starter-jdbc:配置使用jdbc所需的函式庫。 postgresql:配置postgresql連接Driver所需的函式庫。 jasypt-spring-boot-starter:加解密所需的函式庫。 spring-boot-starter-data-jpa:配置Spring data jpa所需的函式庫。

IReport字型下拉選單中文亂碼

這個問題其實也不是很大啦,不過當你有很多的中文字型檔的時候可能就不知道要選哪一個,啟動IReport後,開啟報表後會發現左邊下拉選單中,最下面的字型清單中有出現方框,顯示不出該字型的名稱,這幾個字型應該是判斷新細明體,標楷體及細明體,如下圖 下載IReport的Source Code來檢查一下,it.businesslogic.ireport.gui.MainFrame發現這個JComboBox有特別設定Arial字型,當然只要是中文的都顯示不出來ㄚ,所以點掉這一行後重新編譯,嘿嘿就可以了。 jComboBoxFont.setFont(new java.awt.Font("Arial", 0, 11)); 我目前使用的版本為 IReport-3.0.0-src