[3]AMQP(高级消息队列协议) ----QPID JMS-0.9 API 对 SSL 的支持

原创 2016年07月02日 23:46:27

QPID JMS-0.9 Java的API 版本只支持 AMQP-1-0的协议,那么如何用QPID JMS-0.9 Java的API 去调用QPID的基于SSL的端口的服务呢。一般来说有两种方式,后面将会给出第一种方式的具体代码.

#1 直接设置相应的属性

String truststore_File_Path="D:/QpidSSL/clientts.jks";
String truststore_password="123456";
String keystore_File_Path="D:/QpidSSL/clientks.jks";
String keystore_Password="123456";

#2 通过QPID JMS-0.9 Java的客户端参数配置支持。具体可以参考面的这些参数(具体请参考https://qpid.apache.org/releases/qpid-jms-0.9.0/docs/index.html)

transport.keyStoreLocation default is to read from the system property "javax.net.ssl.keyStore"
transport.keyStorePassword default is to read from the system property "javax.net.ssl.keyStorePassword"
transport.trustStoreLocation default is to read from the system property "javax.net.ssl.trustStore"
transport.trustStorePassword default is to read from the system property "javax.net.ssl.keyStorePassword"
transport.storeType The type of trust store being used. Default is "JKS".
transport.contextProtocol The protocol argument used when getting an SSLContext. Default is "TLS".
transport.enabledCipherSuites The cipher suites to enable, comma separated. No default, meaning the context default ciphers are used. Any disabled ciphers are removed from this.
transport.disabledCipherSuites The cipher suites to disable, comma separated. Ciphers listed here are removed from the enabled ciphers. No default.
transport.enabledProtocols The protocols to enable, comma separated. No default, meaning the context default protocols are used. Any disabled protocols are removed from this.
transport.disabledProtocols The protocols to disable, comma separated. Protocols listed here are removed from the enabled protocols. Default is "SSLv2Hello,SSLv3".
transport.trustAll Whether to trust the provided server certificate implicitly, regardless of any configured trust store. Defaults to false.
transport.verifyHost Whether to verify that the hostname being connected to matches with the provided server certificate. Defaults to true.
transport.keyAlias The alias to use when selecting a keypair from the keystore if required to send a client certificate to the server. No default.


<span style="font-size:14px;">String truststore_File_Path="D:/QpidSSL/clientts.jks";
String truststore_password="123456";
String keystore_File_Path="D:/QpidSSL/clientks.jks";
String keystore_Password="123456";</span>

则 客户端SSL的调用非常的简单. 结合上一章节( [2]AMQP(高级消息队列协议) ----QPID不得不说的事http://blog.csdn.net/chancein007/article/details/51813218)的Sender.java的例子,具体代码如下:

<span style="font-size:14px;">/*
 * 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 copyright 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 copy of the License at
 *   http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
package org.apache.qpid.jms.example.success;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class Sender {
	private static final String USER = "guest";
	private static final String PASSWORD = "guest";
	private static final int DEFAULT_COUNT = 10;
	private static final int DELIVERY_MODE = DeliveryMode.NON_PERSISTENT;

	private Context getContext() {
		String truststore_File_Path="D:/QpidSSL/clientts.jks";
		String truststore_password="123456";
		String keystore_File_Path="D:/QpidSSL/clientks.jks";
		String keystore_Password="123456";
		InitialContext context = null;
		try {
			InputStream resourceAsStream = this.getClass().getResourceAsStream("hello.properties");
			Properties properties = new Properties();
			context = new InitialContext(properties);
		} catch (IOException e) {
			// TODO Auto-generated catch block
		} catch (NamingException e) {
			// TODO Auto-generated catch block
		return context;


	public void publish(int count) {
		try {
			// The configuration for the Qpid InitialContextFactory has been
			// supplied in
			// a jndi.properties file in the classpath, which results in it
			// being picked
			// up automatically by the InitialContext constructor.
			Context context = this.getContext();

			ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup");
			Destination queue = (Destination) context.lookup("myQueueLookup");

			Connection connection = factory.createConnection(USER, PASSWORD);
			connection.setExceptionListener(new MyExceptionListener());

			Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

			MessageProducer messageProducer = session.createProducer(queue);

			long start = System.currentTimeMillis();
			for (int i = 1; i <= count; i++) {
				TextMessage message = session.createTextMessage("Text!");
				messageProducer.send(message, DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);

				if (i % 100 == 0) {
					System.out.println("Sent message " + i);

			long finish = System.currentTimeMillis();
			long taken = finish - start;
			System.out.println("Sent " + count + " messages in " + taken + "ms");

		} catch (Exception exp) {
			System.out.println("Caught exception, exiting.");

	public static void main(String[] args) throws Exception {
		int count = DEFAULT_COUNT;
		if (args.length == 0) {
			System.out.println("Sending up to " + count + " messages.");
					.println("Specify a message count as the program argument if you wish to send a different amount.");
		} else {
			count = Integer.parseInt(args[0]);
			System.out.println("Sending up to " + count + " messages.");
		Sender sender=new Sender();


	private static class MyExceptionListener implements ExceptionListener {
		public void onException(JMSException exception) {
			System.out.println("Connection ExceptionListener fired, exiting.");

版权声明:本文为博主原创文章,未经博主允许不得转载。 http://blog.csdn.net/chancein007/article/details/51813351

qpid 记录

最近在折腾qpid,遇到一些问题,记录一下 1)qpid-proton pqid broker的关系 qpid-proton的核心是Messenger,也就是一个AMQP兼容的开发包(可以作为...
  • yatusiter
  • yatusiter
  • 2014年12月10日 23:23
  • 4805


  • dandanzmc
  • dandanzmc
  • 2016年08月20日 18:49
  • 7203


https://www.rabbitmq.com/tutorials/tutorial-one-python.html  1 "Hello World!" Th...
  • gzhouc
  • gzhouc
  • 2016年05月27日 20:31
  • 743

[2]AMQP(高级消息队列协议) ----QPID不得不说的事

如果说到AMQP协议,则不得不提的就是QPID。QPID的论坛现在十分的活跃,基本上白天提的问题,晚上马上就能得到回复。由此可见QPID的活跃程度。 大家可以到http://qpid.2158936....
  • chancein007
  • chancein007
  • 2016年07月02日 23:35
  • 1423

[1]AMQP(高级消息队列协议) ----入门

  • chancein007
  • chancein007
  • 2016年07月02日 23:09
  • 2664

AMQP学习 & RabbitMQ 与 ActiveMQ、ZeroMQ以及Kafka的比较

之前写了一篇文章关于Active以及消息队列推拉模式的文章,可以参考:link   关于 Active 与 RabbitMQ以及其他的比较,有如下记录:   这篇文章 link...
  • csdn265
  • csdn265
  • 2017年04月12日 17:03
  • 382

Rabbitmq java client编译

Rabbitmq java client编译前言项目中用到了rabbitmq用来做异步任务队列,遇到了一些问题,决定翻阅一下client源码,官方文档提供的build流程不够详细,这里整理一下环境cl...
  • joniers
  • joniers
  • 2017年07月21日 19:11
  • 217


基础 高级消息队列协议(AMQP1)是一个异步消息传递所使用的应用层协议规范,是一个线路层协议,而不是API,不能被开发者直接使用,它的客户端能够无视消息的来源任意发送和接受信息,AMQP的原始用途...
  • maoyeqiu
  • maoyeqiu
  • 2017年04月24日 11:42
  • 731

[4]AMQP(高级消息队列协议) ----改造QPID JMS-0.9 API 对 SSLContext的 支持

默认情况下QPID JMS-0.9 API对SSLConext没有提供相应的接口. 但是在笔者项目中,又需要其对SSLContext对象的支持。这个问问深深的难住了笔者2~3天时间,笔者通过深入的研究...
  • chancein007
  • chancein007
  • 2016年07月03日 00:16
  • 1012

源码安装 OpenStack icehouse Trove 项目

关于 Trove 这个 DbaaS 项目介绍可以看官方 wiki 里介绍。本文主要目的就是把 Trove 能安装上、并且用起来。 https://wiki.openstack.org/wiki/Tr...
  • wuzhongdehua1
  • wuzhongdehua1
  • 2014年10月07日 00:52
  • 5418
您举报文章:[3]AMQP(高级消息队列协议) ----QPID JMS-0.9 API 对 SSL 的支持