「java实现mq」java实现命令行交互

博主:adminadmin 2022-12-02 18:15:07 65

本篇文章给大家谈谈java实现mq,以及java实现命令行交互对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

为什么MQ的编程用JAVA好呢?

作为 MQSeries 应用程序的开发人员,MQSeries Java 编程接口使您能够享用到许多 Java 的优点。

Java 编程语言易于使用。它不需要头文件、指针、结构、联合以及运算符重载。用 Java 写的程序比其同类 C 和 C++ 更容易开发调试。

Java 是面向对象的。Java 的面向对象功能好比 C++,但是它没有多重继承性。实际上,Java 使用的是接口的概念。

Java 是继承性分布的。Java 类库包含了使用 TCP/IP 的协议(如 HTTP, FTP)的例行程序库。 Java 程序能够象访问文件系统那样容易地访问 URL。

Java 是健壮的。Java 非常着重于可能发生问题的早期检查,动态(运行时)检查并消除有出错可能性的情况。 Java 使用引用的概念,它能够消除覆盖内存和破坏数据的可能性。

Java 是安全的。Java 要在网络/分布式环境中运行,并已在安全性问题上下了很大功夫。 Java 程序不能超越其运行时堆栈,不能破坏超过其处理空间的内存,并且当从 Internet 下载时,还不能读写本地文件。

Java 程序是可移植的。Java 规范的特征中没有 “实现相关性”这一条。Java 编译器生成一个体系结构中性的目标文件格式。编译代码可在许多处理器上执行,只要有 Java 运行时系统。

若用 MQSeries Java 编写应用程序,用户可从 Internet 为程序(称为小程序)下载 Java 字节代码,并在其自用的机器上运行。这意味着访问 Web 服务器的用户不需要先在其机器上安装,就能装入并运行应用程序。需要更新程序时,可在 Web 服务器上更新复制,当用户下一次访问小程序时,它们会收到最新的版本。这能够显著地降低成本,而安装并更新传统的客户程序需要涉及大量的桌面。若将小程序置于在企业防火墙外可存取的 Web 服务器上,则无论谁在 Internet 上都可以下载并使用您的应用程序。这代表 MQSeries 系统可从 Internet 上的任何地方获得信息。这打开了建立一组全新的完整 Internet 可存取服务的大门,支持商用程序并使之电子化。

java 监听mq消息 底层是用线程实现的吗

不是通过线程实现的,它是通过一种注册--通知机制实现的。在java的设计模式中,有一种模式叫:观察者模式,和这个类似。举个例子,本例子是一个简单的监听当数据发生变化时要做的操作。

1,我们先定义一个接口,可以让多个监听者实现pre t="code" l="java"public interface IDataListen {

public void update(Object event,Object msg);

}2,实现一监听者

pre t="code" l="java"public class DataListen implements IDataListen{

@Override

public void update(Object event, Object arg) {

// TODO Auto-generated method stub

System.out.println("数据发生了变化");

}

}3,被监听者

pre t="code" l="java"public class DataManager{

private ListIDataListen listenList = new ArrayList();

public void notifyListen(Object event,Object msg){

for(IDataListen dataListen : listenList){

dataListen.update(null, null);

}

}

public void addListen(IDataListen dataListen){

listenList.add(dataListen);

}

public void updateData(Object msg){

this.notifyListen(null, msg);

}

public static void main(String[] args) {

DataManager dataManager = new DataManager();

IDataListen dataListen1 = new DataListen();

IDataListen dataListen2 = new DataListen();

dataManager.addListen(dataListen1);

dataManager.addListen(dataListen2);

dataManager.updateData("aaa");

}

}main方法里面是监听的应用。这样就可以监听DataManager中的updateData行为了,当有数据发生变化时,就可以即时被监听者收到。

java 怎么样调用IBM MQ 或者通信问题

websphere mq : 用于传输信息 具有跨平台的功能。

1 安装websphere mq 并启动

2 websphere mq 建立 queue Manager (如:MQSI_SAMPLE_QM)

3 建立queue 类型选择 Local类型 的 (如lq )

3 建立channels 类型选择Server Connection (如BridgeChannel)

java 代码如下:

package test.mq;

import com.ibm.mq.*;

/*

* 成功的访问mq 的java 类

*/

public class FirstMqTest {

// public static void main(String[] args[]){

// FirstMqTest first = new FirstMqTest();

// first.test();

// }

public static void main(String args[]){

FirstMqTest first = new FirstMqTest();

first.test();

}

public void test(){

String qManager = "MQSI_SAMPLE_QM"; //QueueManager name

String qName = "lq";//Queue Name

try {

//configure connection parameters

MQEnvironment.hostname="172.16.17.123";//MQ Server name or IP

//MQEnvironment.port=1414;//listenr port

MQEnvironment.channel="BridgeChannel";//Server-Connection Channel

MQEnvironment.CCSID =1381;

// Create a connection to the QueueManager

System.out.println("Connecting to queue manager: "+qManager);

MQQueueManager qMgr = new MQQueueManager(qManager);

// Set up the options on the queue we wish to open

int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;

// Now specify the queue that we wish to open and the open options

System.out.println("Accessing queue: "+qName);

MQQueue queue = qMgr.accessQueue(qName, openOptions);

// Define a simple WebSphere MQ Message ...

MQMessage msg = new MQMessage();

// ... and write some text in UTF8 format

msg.writeUTF("Hello, World!");

// Specify the default put message options

MQPutMessageOptions pmo = new MQPutMessageOptions();

// Put the message to the queue

System.out.println("Sending a message...");

/*

* 在此测试一下 mq 的传输次列

*

*/

for(int j=0;j 5;j++){

String str ="test11111111111";

str = str+j;

msg.writeUTF(str);

queue.put(msg, pmo);

}

queue.put(msg, pmo);

// Now get the message back again. First define a WebSphere MQ message

// to receive the data

MQMessage rcvMessage = new MQMessage();

// Specify default get message options

MQGetMessageOptions gmo = new MQGetMessageOptions();

// Get the message off the queue.

System.out.println("...and getting the message back again");

queue.get(rcvMessage, gmo);

// And display the message text...

String msgText = rcvMessage.readUTF();

System.out.println("The message is: " + msgText);

// Close the queue

System.out.println("Closing the queue");

queue.close();

// Disconnect from the QueueManager

System.out.println("Disconnecting from the Queue Manager");

qMgr.disconnect();

System.out.println("Done!");

}

catch (MQException ex) {

System.out.println("A WebSphere MQ Error occured : Completion Code "

+ ex.completionCode + " Reason Code " + ex.reasonCode);

}

catch (java.io.IOException ex) {

System.out.println("An IOException occured whilst writing to the message buffer: "

+ ex);

}

}

}

JAVA利用ActiveMQ达到实时更新状态

我们以前这么做的. Socket 传和收数据. 我们是在struts的action里面 开启socket的 然后发送数据 等待返回的数据 然后在显示数据.

至于修改 那也一样的action处理数据 发送数据 等待接收数据.

在进行通信的时候 进制之间的转换 是很常见的 .

java实现mq的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java实现命令行交互、java实现mq的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-02,除非注明,否则均为首码项目网原创文章,转载请注明出处。