1. c语言能读取apache activeMQ队列数据吗请说的具体点
可以的,参见apache的网站。
2. C#怎么监听ActiveMq连接异常
JMS 程序的最终目的是生产和消费的消息能被其他程序使用,JMS 的 Message 是一个既简单又不乏灵活性的基本格式,允许创建不同平台上符合非JMS 程序格式的消息。
Message 由消息头,属性和消息体三部份组成。
Active MQ支持过滤机制,即生产者可以设置消息的属性(Properties),该属性与消费者端的Selector对应,只有消费者设置的selector与消息的Properties匹配,消息才会发给该消费者。Topic和Queue都支持Selector。
示例代码
[csharp] view plain print?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Apache.NMS;
using System.Diagnostics;
using Apache.NMS.Util;
using System.Windows.Threading;
/*
* 功能描述:C#使用ActiveMQ示例
* 修改次数:2
* 最后更新: by Kagula,2012-07-31
*
* 前提条件:
* [1]apache-activemq-5.4.2
* [2]Apache.NMS.ActiveMQ-1.5.6-bin
* [3]WinXP SP3
* [4]VS2008 SP1
* [5]WPF工程 With .NET Framework 3.5
*
* 启动
*
* 不带安全控制方式启动
* [你的解压路径]\apache-activemq-5.4.2\bin\activemq.bat
*
* 安全方式启动
* 添加环境变量: ACTIVEMQ_ENCRYPTION_PASSWORD=activemq
* [你的解压路径]\apache-activemq-5.4.2\bin>activemq xbean:file:../conf/activemq-security.xml
*
* Active MQ 管理地址
* http://127.0.0.1:8161/admin/
* 添加访问"http://127.0.0.1:8161/admin/"的限制
*
* 第一步:添加访问限制
* 修改D:\apache\apache-activemq-5.4.2\conf\jetty.xml文件
* 下面这行编码,原
* <property name="authenticate" value="true" />
* 修改为
* <property name="authenticate" value="false" />
*
* 第二步:修改登录用户名密码,缺省分别为admin,admin
* D:\apache\apache-activemq-5.4.2\conf\jetty-realm.properties
*
* 用户管理(前提:以安全方式启动ActiveMQ)
*
* 在[你的解压路径]\apache-activemq-5.4.2\conf\credentials.properties文件中修改默认的用户名密码
* 在[你的解压路径]\apache-activemq-5.4.2\conf\activemq-security.xml文件中可以添加新的用户名
* e.g. 添加oa用户,密码同用户名。
* <authenticationUser username="oa" password="oa" groups="users,admins"/>
*
* 在[你的解压路径]\apache-activemq-5.4.2\conf\activemq-security.xml文件中你还可以设置指定的Topic或Queue
* 只能被哪些用户组read 或 write。
*
*
* 配置C# with WPF项目
* 项目的[Application]->[TargetFramework]属性设置为[.NETFramework 3.5](这是VS2008WPF工程的默认设置)
* 添加[你的解压路径]\Apache.NMS.ActiveMQ-1.5.6-bin\lib\Apache.NMS\net-3.5\Apache.NMS.dll的引用
* Apache.NMS.dll相当于接口
*
* 如果是以Debug方式调试
* 把[你的解压路径]\Apache.NMS.ActiveMQ-1.5.6-bin\build\net-3.5\debug\目录下的
* Apache.NMS.ActiveMQ.dll文件复制到你项目的Debug目录下
* Apache.NMS.ActiveMQ.dll相当于实现
*
* 如果是以Release方式调试
* 参考上文,去取Apache.NMS,Release目录下相应的DLL文件,并复制到你项目的Release目录下。
*
*
* 参考资料
* [1]《C#调用ActiveMQ官方示例》 http://activemq.apache.org/nms/examples.html
* [2]《ActiveMQ NMS下载地址》http://activemq.apache.org/nms/activemq-downloads.html
* [3]《Active MQ在C#中的应用》http://www.cnblogs.com/guthing/archive/2010/06/17/1759333.html
* [4]《NMS API Reference》http://activemq.apache.org/nms/nms-api.html
*/
namespace testActiveMQSubscriber
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
private static IConnectionFactory connFac;
private static IConnection connection;
private static ISession session;
private static IDestination destination;
private static IMessageProcer procer;
private static IMessageConsumer consumer;
protected static ITextMessage message = null;
public Window1()
{
InitializeComponent();
initAMQ("MyFirstTopic");
}
private void initAMQ(String strTopicName)
{
try
{
connFac = new NMSConnectionFactory(new Uri("activemq:failover:(tcp://localhost:61616)"));
//新建连接
//connection = connFac.CreateConnection("oa","oa");//设置连接要用的用户名、密码
//如果你要持久“订阅”,则需要设置ClientId,这样程序运行当中被停止,恢复运行时,能拿到没接收到的消息!
connection.ClientId = "testing listener";
connection = connFac.CreateConnection();//如果你是缺省方式启动Active MQ服务,则不需填用户名、密码
//创建Session
session = connection.CreateSession();
//发布/订阅模式,适合一对多的情况
destination = SessionUtil.GetDestination(session, "topic://" + strTopicName);
//新建生产者对象
procer = session.CreateProcer(destination);
procer.DeliveryMode = MsgDeliveryMode.NonPersistent;//ActiveMQ服务器停止工作后,消息不再保留
3. 启动activeMQ报错,每次重启电脑好几次才能启动MQ,该怎么解决
ActiveMQ 安装windwos服务不能启动问题
一.AcitveMQ windwos 服务
1.安装目录下新建 temp文件夹
2.安装目录下\bin\win32\wrapper.conf指定java.io.tempdir目录
wrapper.java.additional.10=-Djava.io.tmpdir="%ACTIVEMQ_HOME%/temp"
# ------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding right ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a of the License at
#
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------
#********************************************************************
# Wrapper Properties
#********************************************************************
#wrapper.debug=TRUE
set.default.ACTIVEMQ_HOME=../..
set.default.ACTIVEMQ_BASE=../..
wrapper.working.dir=.
# Java Application
wrapper.java.command=java
# Java Main class. This class must implement the WrapperListener interface
# or guarantee that the WrapperManager class is initialized. Helper
# classes are provided to do this for you. See the Integration section
# of the documentation for details.
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
wrapper.java.classpath.1=%ACTIVEMQ_HOME%/bin/wrapper.jar
wrapper.java.classpath.2=%ACTIVEMQ_HOME%/bin/run.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=%ACTIVEMQ_HOME%/bin/win32
# Java Additional Parameters
# note that n is the parameter number starting from 1.
wrapper.java.additional.1=-Dactivemq.home="%ACTIVEMQ_HOME%"
wrapper.java.additional.2=-Dactivemq.base="%ACTIVEMQ_BASE%"
wrapper.java.additional.3=-Djavax.net.ssl.keyStorePassword=password
wrapper.java.additional.4=-Djavax.net.ssl.trustStorePassword=password
wrapper.java.additional.5=-Djavax.net.ssl.keyStore="%ACTIVEMQ_BASE%/conf/broker.ks"
wrapper.java.additional.6=-Djavax.net.ssl.trustStore="%ACTIVEMQ_BASE%/conf/broker.ts"
wrapper.java.additional.7=-Dcom.sun.management.jmxremote
wrapper.java.additional.8=-Dorg.apache.activemq.UseDedicatedTaskRunner=true
wrapper.java.additional.9=-Djava.util.logging.config.file=logging.properties
wrapper.java.additional.10=-Djava.io.tmpdir="%ACTIVEMQ_HOME%/temp"
# Uncomment to enable remote jmx
#wrapper.java.additional.n=-Dcom.sun.management.jmxremote.port=1616
#wrapper.java.additional.n=-Dcom.sun.management.jmxremote.authenticate=false
#wrapper.java.additional.n=-Dcom.sun.management.jmxremote.ssl=false
# Uncomment to enable YourKit profiling
#wrapper.java.additional.n=-Xrunyjpagent
# Uncomment to enable remote debugging
#wrapper.java.additional.n=-Xdebug -Xnoagent -Djava.compiler=NONE
#wrapper.java.additional.n=-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3
# Maximum Java Heap Size (in MB)
wrapper.java.maxmemory=512
# Application parameters. Add parameters as needed starting from 1
wrapper.app.parameter.1=org.apache.activemq.console.Main
wrapper.app.parameter.2=start
#********************************************************************
# Wrapper Logging Properties
#********************************************************************
# Format of output for the console. (See docs for formats)
wrapper.console.format=PM
# Log Level for console output. (See docs for log levels)
wrapper.console.loglevel=INFO
# Log file to use for wrapper output logging.
wrapper.logfile=%ACTIVEMQ_BASE%/data/wrapper.log
# Format of output for the log file. (See docs for formats)
wrapper.logfile.format=LPTM
# Log Level for log file output. (See docs for log levels)
wrapper.logfile.loglevel=INFO
# Maximum size that the log file will be allowed to grow to before
# the log is rolled. Size is specified in bytes. The default value
# of 0, disables log rolling. May abbreviate with the 'k' (kb) or
# 'm' (mb) suffix. For example: 10m = 10 megabytes.
wrapper.logfile.maxsize=0
# Maximum number of rolled log files which will be allowed before old
# files are deleted. The default value of 0 implies no limit.
wrapper.logfile.maxfiles=0
# Log Level for sys/event log output. (See docs for log levels)
wrapper.syslog.loglevel=NONE
#********************************************************************
# Wrapper Windows Properties
#********************************************************************
# Title to use when running as a console
wrapper.console.title=ActiveMQ
#********************************************************************
# Wrapper Windows NT/2000/XP Service Properties
#********************************************************************
# WARNING - Do not modify any of these properties when an application
# using this configuration file has been installed as a service.
# Please uninstall the service before modifying this section. The
# service can then be reinstalled.
# Name of the service
wrapper.ntservice.name=ActiveMQ
# Display name of the service
wrapper.ntservice.displayname=ActiveMQ
# Description of the service
wrapper.ntservice.description=ActiveMQ Broker
# Service dependencies. Add dependencies as needed starting from 1
wrapper.ntservice.dependency.1=
# Mode in which the service is installed. AUTO_START or DEMAND_START
wrapper.ntservice.starttype=AUTO_START
# Allow the service to interact with the desktop.
wrapper.ntservice.interactive=false
4.出现如下错误 Unable to execute Java command. 系统找不到指定的文件。 (0x2)
5.指定Java安装路径
wrapper.java.command=C:/Program Files/Java/jdk1.7.0_25/bin/java
# ------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding right ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a of the License at
#
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------
#********************************************************************
# Wrapper Properties
#********************************************************************
# wrapper.debug=TRUE
set.default.ACTIVEMQ_HOME=../..
set.default.ACTIVEMQ_BASE=../..
wrapper.working.dir=.
# Java Application
wrapper.java.command=C:/Program Files/Java/jdk1.7.0_25/bin/java
# Java Main class. This class must implement the WrapperListener interface
# or guarantee that the WrapperManager class is initialized. Helper
# classes are provided to do this for you. See the Integration section
# of the documentation for details.
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
wrapper.java.classpath.1=%ACTIVEMQ_HOME%/bin/wrapper.jar
wrapper.java.classpath.2=%ACTIVEMQ_HOME%/bin/run.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=%ACTIVEMQ_HOME%/bin/win32
# Java Additional Parameters
# note that n is the parameter number starting from 1.
wrapper.java.additional.1=-Dactivemq.home="%ACTIVEMQ_HOME%"
wrapper.java.additional.2=-Dactivemq.base="%ACTIVEMQ_BASE%"
wrapper.java.additional.3=-Djavax.net.ssl.keyStorePassword=password
wrapper.java.additional.4=-Djavax.net.ssl.trustStorePassword=password
wrapper.java.additional.5=-Djavax.net.ssl.keyStore="%ACTIVEMQ_BASE%/conf/broker.ks"
wrapper.java.additional.6=-Djavax.net.ssl.trustStore="%ACTIVEMQ_BASE%/conf/broker.ts"
wrapper.java.additional.7=-Dcom.sun.management.jmxremote
wrapper.java.additional.8=-Dorg.apache.activemq.UseDedicatedTaskRunner=true
wrapper.java.additional.9=-Djava.util.logging.config.file=logging.properties
wrapper.java.additional.10=-Djava.io.tmpdir="%ACTIVEMQ_HOME%/temp"
# Uncomment to enable remote jmx
#wrapper.java.additional.n=-Dcom.sun.management.jmxremote.port=1616
#wrapper.java.additional.n=-Dcom.sun.management.jmxremote.authenticate=false
#wrapper.java.additional.n=-Dcom.sun.management.jmxremote.ssl=false
# Uncomment to enable YourKit profiling
#wrapper.java.additional.n=-Xrunyjpagent
# Uncomment to enable remote debugging
#wrapper.java.additional.n=-Xdebug -Xnoagent -Djava.compiler=NONE
#wrapper.java.additional.n=-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3
# Maximum Java Heap Size (in MB)
4. 如何学习activemq
1)普通启动
cd /home/manorage/ apache-activemq-5.3.0
bin/ activemq
(2).指定日志文件的启动方式
bin/activemq >tmp/smlog 2>&1 &
(3)后台启动方式
nohup bin/activemq >tmp/smlog 2>&1 &
这里需要注意:前两种启动方式在linix命令行或者通过ssh客户端启动时在关闭对应的窗口时activemq会关闭,甚至直接输入ctrl+c也会导致activemq退出;第三种则不会出现这中情况。
5. mq 能用于c编程么
PCF就支持C呀!
MQ还提供了系统管理的编程接口,通过该接口用户可以编写应用程序从而进行自动化的实时监控及管理。MQ的系统管理接口有两种,即Programmable Command Format(可编程命令格式,简称PCF)和MQ Administration Interface(MQ管理接口,简称MQAI)。
关于WebSphere MQ 可编程命令格式(PCF)
WebSphere MQ 可编程命令格式(PCF)命令使得管理任务能编写到应用程序中,在程序中可以创建队列、进程等对象的定义以及更改对象的属性等。
PCF定义了命令和回复消息,应用程序通过这些命令和回复消息实现和队列管理器之间的信息交换,PCF 命令和MQSC 命令具有相同的命令集,所有通过MQSC命令能够实现的功能,通过PCF都可以实现,因此,通过WebSphere MQ的应用程序可以实现对MQ对象的管理包括:队列管理器,进程定义,队列和通道等。PCF命令可以被发送到本地队列管理器的命令队列,也可以被发送到某个远程队列管理器的命令队列,因此,应用程序可以通过一个本地队列管理器集中管理网络中的任何本地和远程管理器。
MQ的远程管理机制底层就是通过PCF这种方式的,在互相联接的系统中的任意一个节点都可以进行对其他所有节点的配置和管理,这种情形的典型应用就是通过一台Windows操作系统的机器来管理全网的MQ节点。由于MQ在Windows XP/NT/2000平台上提供了图形界面的管理工具,我们可以把一个节点设成管理机,利用管理机可以监控和配置网络中的任一节点,监测和显示整个网络中任何一个节点上的服务器及其各种对象的状态和运行情况,从而实现对中间件的集中管理和监控。
每一个队列管理器有一个名为SYSTEM.ADMIN.COMMAND.QUEUE的管理队列,应用程序可以按照PCF命令消息格式封装的要求,组成PCF消息,并将该PCF命令消息发送到管理队列中,同时,每一个队列管理器也有一个命令服务器(Command Server),它为管理队列中的消息提供服务,在我们使用MQ的控制命令strmqcsv启动命令服务器之后,它将监控管理队列,一旦该队列中有PCF消息到达,它将读取该消息,并解释执行。因此在网络中的任何队列管理器都可以处理PCF消息,通过使用指定的回复队列,回复消息可以被返回给应用程序,应用程序可以获知PCF命令执行成功与否。回复队列由命令消息的消息描述符(MQMD)中的ReplyToQ和ReplyToQMgr两个字段来指定。
PCF命令和回复消息是使用MQ相应的编程接口进行发送和接收的,以C语言为例,我们只需要使用MQPUT将PCF命令消息发送到相应的管理队列,使用MQGET将PCF回复消息从相应的回复队列中取出即可。这里的关键就是如何封装PCF消息。每个MQ指令及其相关参数都是一条单独的命令消息,每个命令消息由PCF头和若干个参数结构块组成,每个参数结构块提供了命令的参数。回复消息的结构与命令消息相同,但是回复消息的个数根据不同的情况可能会有多个,例如:如果我们查询某个队列管理器下所有本地队列的属性,假设本地队列有10个,那么我们将得到10个回复消息,PCF头中的Control字段MQCFC_NOT_LAST和MQCFC_LAST将用于区分是否为最后一个回复消息。
PCF编程接口支持C,Visual Basic, COBOL, RPG, PL/1和Java等,其中在我们最常用的编程语言中,C和Visual Basic编程在PCF的封装上相对Java将会略微复杂一些
6. 请用白话讲解ActiveMQ的用途
用途就是用来处理消息,也就是处理JMS的。消息队列在大型电子商务类网站,如京东、淘宝、去哪儿等网站有着深入的应用,队列的主要作用是消除高并发访问高峰,加快网站的响应速度。
在不使用消息队列的情况下,用户的请求数据直接写入数据库,高发的情况下,会对数据库造成巨大的压力,同时也使得系统响应延迟加剧,但使用队列后,用户的请求发给队列后立即返回。
例如:不能直接给用户提示订单提交成功,京东上提示:“您提交了订单,请等待系统确认”再由消息队列的消费者进程从消息队列中获取数据,异步写入数据库。
由于消息队列的服务处理速度远快于数据库,因此用户的响应延迟可得到有效改善。
(6)c语言activemq客户端扩展阅读:
ActiveMQ主要有以下几种使用场景
1、异步调用。
2、一对多通信。
3、做多个系统的集成、同构、异构。
4、作为RPC的替代。
5、多个应用相互解耦。
6、作为事件驱动架构的幕后支撑。
7、为了提高系统的可伸缩性。
7. 如果在程序中查看ActiveMQ中消费者是否在线
如果是C/S的结构,你的服务端和客户端应该是Socket连接,可以利用心跳来保持服务端和客户端的连接,已确定客户端是否存在
8. 消息队列(mq)是什么
是生产者先将消息投递一个叫队列的容器中,然后再从这个容器中取出消息,最后再转发给消费者。
消息队列是 Microsoft 的消息处理技术,它在任何安装 Microsoft Windows 的计算机组合中,为任何应用程序提供消息处理和消息队列功能,无论这些计算机是否在同一个网络上或者是否同时联机。
消息队列网络是能够相互间来回发送消息的任何一组计算机。网络中的不同计算机在确保消息顺利处理的过程中扮演不同的角色。它们中有些提供路由信息以确定如何发送消息,有些保存整个网络的重要信息,而有些只是发送和接收消息。
消息队列的类型介绍:
消息队列目前主要有两种类型:POSIX消息队列以及系统V消息队列,系统V消息队列目前被大量使用。每个消息队列都有一个队列头,用结构struct msg_queue来描述。队列头中包含了该消息队列的大量信息。包括消息队列键值、用户ID、组ID、消息队列中消息数目等等。
消息队列就是一个消息的链表,可以把消息看作一个记录,具有特定的格式以及特定的优先级。对消息队列有写权限的进程可以向消息队列中按照一定的规则添加新消息;对消息队列有读权限的进程则可以从消息队列中读走消息。消息队列是随内核持续的。
9. 如何用C调用activemq通信
我有一次在MQ的官方网站上找东西的时候看到有C++调用MQ的说明,你去官方网站上看看
10. 用ActiveMQ实现聊天单了还有群聊实现的思路
A、B、C会有一个唯一的ID比如A是1,B是2,C是3,简单的,假如A发消息给B,有两种可能,B不在线和B在线,情况1:B会提前跟A说,我的编号是2,有消息直接给我:或者有消息的话,先帮我留着,我回来再给我。复杂的:群聊:房间的每个人都各自报自己的编号,根据他们分配一个组,不管在哪个组,大家都很熟,直接发消息对号入座,假如A、B、C是一个组,那么久把这个组的人假如到一个List集合群里面,后者来一个就add一个,走一个就remove一个。List集合群就放groupId,和一个Map成员对象,假如A发消息,那么闲遍历A在哪个groupId组里面,然后根据组遍历,组里面的所有人。然后开始叫B、C。如果B、C不回答,那么久是离线状态,activeMQ有个叫订阅的,下次那个不在的,上来,就会直接下达消息给他。我没用过,但我最近也要用上群聊,我的大致想法是这样