当前位置: 首页 > news >正文

oracle aq java jms使用(数据类型为XMLTYPE)

记录一次冷门技术oracle aq的使用

版本

oracle 11g

创建用户

-- 创建用户
create user testaq identified by 123456;
grant connect, resource to testaq;-- 创建aq所需要的权限
grant execute on dbms_aq to testaq;
grant execute on dbms_aqadm to testaq;
begindbms_aqadm.grant_system_privilege('enqueue_any', 'testaq', false);dbms_aqadm.grant_system_privilege('dequeue_any', 'testaq', false);
end;grant execute on dbms_aq to testaq;
grant resource to testaq;
grant connect to testaq;
grant execute any procedure to testaq;
grant aq_administrator_role to testaq;
grant aq_user_role to testaq;
grant execute on dbms_aqadm to testaq;
grant execute on dbms_aq to testaq;
grant execute on dbms_aqin to testaq;
grant create procedure to testaq;
grant create procedure to testaq with admin option;

创建列队表

begindbms_aqadm.create_queue_table(queue_table   => 'testaq.xml_queue_table',queue_payload_type => 'SYS.XMLTYPE',multiple_consumers => false);
end;

创建列队及启动队列

begindbms_aqadm.create_queue (queue_name  => 'testaq.xml_queue',queue_table => 'testaq.xml_queue_table');dbms_aqadm.start_queue(queue_name  =>  'testaq.xml_queue');
end;

停止及删除队列

begindbms_aqadm.stop_queue (queue_name => 'testaq.xml_queue');dbms_aqadm.drop_queue (queue_name => 'testaq.xml_queue');dbms_aqadm.drop_queue_table (queue_table => 'testaq.xml_queue_table');
end;

发送消息

declarer_enqueue_options DBMS_AQ.ENQUEUE_OPTIONS_T;r_message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;v_message_handle RAW(16);o_payload SYS.XMLTYPE;
begino_payload := SYS.XMLTYPE('<ROOT><ROWSET><ROW><APPLYNO>test</APPLYNO></ROW></ROWSET></ROOT>');dbms_aq.enqueue(queue_name  => 'testaq.test_queue',enqueue_options => r_enqueue_options,message_properties => r_message_properties,payload => o_payload,msgid => v_message_handle);commit;
end;

Java接收消息

oracle-aq:jdbcUrl: jdbc:oracle:thin:@localhost:1521:testaqusername: testaqpassword: 123456queueNameUser: testaqqueueName: xml_queue
@Component
@ConfigurationProperties(prefix = "oracle-aq")
@Data
public class OracleAqJmsConfig {private String jdbcUrl;private String username;private String password;private String queueNameUser;private String queueName;
}
import lombok.extern.slf4j.Slf4j;
import oracle.jms.AQjmsAdtMessage;
import oracle.jms.AQjmsDestination;
import oracle.jms.AQjmsFactory;
import oracle.jms.AQjmsSession;
import oracle.xdb.XMLType;
import oracle.xdb.XMLTypeFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import javax.jms.*;
import javax.xml.bind.JAXBException;
import java.util.Properties;@Service
@Slf4j
public class TestOracleAq {@Autowiredprivate OracleAqJmsConfig config;@PostConstructpublic void messageListener() throws JMSException {QueueConnectionFactory queueConnectionFactory = AQjmsFactory.getQueueConnectionFactory(config.getJdbcUrl(), new Properties());QueueConnection conn = queueConnectionFactory.createQueueConnection(config.getUsername(), config.getPassword());AQjmsSession session = (AQjmsSession)conn.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);conn.start();Queue queue = (AQjmsDestination)session.getQueue(config.getQueueNameUser(), config.getQueueName());XMLTypeFactory factory = new XMLTypeFactory();MessageConsumer consumer = session.createConsumer(queue, null, factory, null, false);consumer.setMessageListener(new MessageListener() {@Overridepublic void onMessage(Message message) {AQjmsAdtMessage adtMessage = (AQjmsAdtMessage) message;try {Object adtPayload = adtMessage.getAdtPayload();XMLType xmlType = (XMLType)adtPayload;saveXml(xmlType.getStringVal());log.info("接收到oracle aq数据:{}", xmlType.getStringVal());} catch (Exception e) {log.error("", e);}}});}public void saveXml(String xml) throws JAXBException {// todo ...}}

依赖

在oracle安装目录中查找这些依赖
在这里插入图片描述

<!-- oracle aq --><dependency><groupId>com.oracle</groupId><artifactId>ojdbc6</artifactId><version>11.1.0.7.0</version><scope>system</scope><systemPath>${project.basedir}/libs/ojdbc6.jar</systemPath>
</dependency>
<dependency><groupId>com.oracle</groupId><artifactId>jmscommon</artifactId><version>1.0</version><scope>system</scope><systemPath>${project.basedir}/libs/jmscommon.jar</systemPath>
</dependency>
<dependency><groupId>com.oracle</groupId><artifactId>orai18n</artifactId><version>11.1.0.7.0</version><scope>system</scope><systemPath>${project.basedir}/libs/orai18n.jar</systemPath>
</dependency>
<dependency><groupId>com.oracle</groupId><artifactId>jta</artifactId><version>1.0</version><scope>system</scope><systemPath>${project.basedir}/libs/jta.jar</systemPath>
</dependency>
<dependency><groupId>com.oracle</groupId><artifactId>aqapi_g</artifactId><version>1.0</version><scope>system</scope><systemPath>${project.basedir}/libs/aqapi_g.jar</systemPath>
</dependency>
<dependency><groupId>oracle.xdb</groupId><artifactId>xdb</artifactId><version>21.9.0.0</version><scope>system</scope><systemPath>${project.basedir}/libs/xdb.jar</systemPath>
</dependency>
<!-- oracle aq -->

相关文章:

  • 使用AppleScript自动滚动预览
  • 关于“Python”的核心知识点整理大全26
  • 【数据结构】八大排序之直接插入排序算法
  • 正则表达式入门与实践
  • C 库函数 - time()
  • 06 Rust 枚举类
  • dapper使用Insert或update时部分字段不映射到数据库
  • 什么是Symbol?在实际开发中怎么用?
  • 软件设计师——信息安全(一)
  • java.lang.ClassNotFoundException:javax.xml.bind.DatatypeConverter 报错解决
  • 数据库原理与应用——简答题练习(数据管理技术发展、数据库主要特征、数据模型、关系模型、实体性之间的关系、DBMS的功能、相关术语解释、数据库系统)
  • arcgis api for js 中使用API的代理页面(跨越配置)
  • 【docker 】Dockerfile指令学习
  • 爬虫工作量由小到大的思维转变---<第三章 搞多大的盘>
  • c++程序设计定义一个 (图书)类,在该类定义中包括
  • docker容器内的网络抓包
  • JDK 6和JDK 7中的substring()方法
  • Laravel核心解读--Facades
  • Linux编程学习笔记 | Linux多线程学习[2] - 线程的同步
  • niucms就是以城市为分割单位,在上面 小区/乡村/同城论坛+58+团购
  • PHP的类修饰符与访问修饰符
  • React-生命周期杂记
  • Spark VS Hadoop:两大大数据分析系统深度解读
  • 表单中readonly的input等标签,禁止光标进入(focus)的几种方式
  • 纯 javascript 半自动式下滑一定高度,导航栏固定
  • 排序算法之--选择排序
  • 设计模式(12)迭代器模式(讲解+应用)
  • 算法---两个栈实现一个队列
  • 通过git安装npm私有模块
  • 微信公众号开发小记——5.python微信红包
  • 微信小程序开发问题汇总
  • 《天龙八部3D》Unity技术方案揭秘
  • #includecmath
  • %check_box% in rails :coditions={:has_many , :through}
  • (1/2)敏捷实践指南 Agile Practice Guide ([美] Project Management institute 著)
  • (13)[Xamarin.Android] 不同分辨率下的图片使用概论
  • (C语言)字符分类函数
  • (第61天)多租户架构(CDB/PDB)
  • (教学思路 C#之类三)方法参数类型(ref、out、parmas)
  • (免费领源码)Python#MySQL图书馆管理系统071718-计算机毕业设计项目选题推荐
  • (转)http协议
  • (转)Spring4.2.5+Hibernate4.3.11+Struts1.3.8集成方案一
  • .bat批处理(二):%0 %1——给批处理脚本传递参数
  • .helper勒索病毒的最新威胁:如何恢复您的数据?
  • .net Application的目录
  • .NET C# 操作Neo4j图数据库
  • .NET gRPC 和RESTful简单对比
  • .NET Remoting学习笔记(三)信道
  • .NET 的程序集加载上下文
  • .Net的DataSet直接与SQL2005交互
  • .NET简谈互操作(五:基础知识之Dynamic平台调用)
  • .Net组件程序设计之线程、并发管理(一)
  • .sh 的运行
  • .xml 下拉列表_RecyclerView嵌套recyclerview实现二级下拉列表,包含自定义IOS对话框...
  • :O)修改linux硬件时间