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

2023-12-17 19:01

本文主要是介绍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 -->

这篇关于oracle aq java jms使用(数据类型为XMLTYPE)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/505481

相关文章

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

Java实现删除文件中的指定内容

《Java实现删除文件中的指定内容》在日常开发中,经常需要对文本文件进行批量处理,其中,删除文件中指定内容是最常见的需求之一,下面我们就来看看如何使用java实现删除文件中的指定内容吧... 目录1. 项目背景详细介绍2. 项目需求详细介绍2.1 功能需求2.2 非功能需求3. 相关技术详细介绍3.1 Ja

springboot项目中整合高德地图的实践

《springboot项目中整合高德地图的实践》:本文主要介绍springboot项目中整合高德地图的实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一:高德开放平台的使用二:创建数据库(我是用的是mysql)三:Springboot所需的依赖(根据你的需求再

spring中的ImportSelector接口示例详解

《spring中的ImportSelector接口示例详解》Spring的ImportSelector接口用于动态选择配置类,实现条件化和模块化配置,关键方法selectImports根据注解信息返回... 目录一、核心作用二、关键方法三、扩展功能四、使用示例五、工作原理六、应用场景七、自定义实现Impor

SpringBoot3应用中集成和使用Spring Retry的实践记录

《SpringBoot3应用中集成和使用SpringRetry的实践记录》SpringRetry为SpringBoot3提供重试机制,支持注解和编程式两种方式,可配置重试策略与监听器,适用于临时性故... 目录1. 简介2. 环境准备3. 使用方式3.1 注解方式 基础使用自定义重试策略失败恢复机制注意事项

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

在Windows上使用qemu安装ubuntu24.04服务器的详细指南

《在Windows上使用qemu安装ubuntu24.04服务器的详细指南》本文介绍了在Windows上使用QEMU安装Ubuntu24.04的全流程:安装QEMU、准备ISO镜像、创建虚拟磁盘、配置... 目录1. 安装QEMU环境2. 准备Ubuntu 24.04镜像3. 启动QEMU安装Ubuntu4

使用Python和OpenCV库实现实时颜色识别系统

《使用Python和OpenCV库实现实时颜色识别系统》:本文主要介绍使用Python和OpenCV库实现的实时颜色识别系统,这个系统能够通过摄像头捕捉视频流,并在视频中指定区域内识别主要颜色(红... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间详解

Windows下C++使用SQLitede的操作过程

《Windows下C++使用SQLitede的操作过程》本文介绍了Windows下C++使用SQLite的安装配置、CppSQLite库封装优势、核心功能(如数据库连接、事务管理)、跨平台支持及性能优... 目录Windows下C++使用SQLite1、安装2、代码示例CppSQLite:C++轻松操作SQ

SpringBoot整合Flowable实现工作流的详细流程

《SpringBoot整合Flowable实现工作流的详细流程》Flowable是一个使用Java编写的轻量级业务流程引擎,Flowable流程引擎可用于部署BPMN2.0流程定义,创建这些流程定义的... 目录1、流程引擎介绍2、创建项目3、画流程图4、开发接口4.1 Java 类梳理4.2 查看流程图4