DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Distributed Rate Limiting in Java: A Deep Dive into Bucket4j + PostgreSQL
  • Data Storage and Indexing in PostgreSQL: Practical Guide With Examples and Performance Insights
  • Monorepo Development With React, Node.js, and PostgreSQL With Prisma and ClickHouse
  • Comparing Managed Postgres Options on The Azure Marketplace

Trending

  • Self-Supervised Learning Techniques
  • Stabilizing ETL Pipelines With Airflow, Presto, and Metadata Contracts
  • Lessons Learned in Test-Driven Development
  • Reducing Hallucinations Using Prompt Engineering and RAG
  1. DZone
  2. Data Engineering
  3. Databases
  4. JDBC Master-Slave Persistence Setup With ActiveMQ Using PostgreSQL

JDBC Master-Slave Persistence Setup With ActiveMQ Using PostgreSQL

Learn how to set up JDBC persistence for ActiveMQ using the PostgreSQL database in just ten quick and easy steps.

By 
Chandra Shekhar Pandey user avatar
Chandra Shekhar Pandey
·
Oct. 06, 17 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
7.9K Views

Join the DZone community and get the full member experience.

Join For Free

This article will help in setting up JDBC master/slave for embedded ActiveMQ in Red Hat JBoss Fuse/AMQ 6.3 with PostgreSQL database from scratch.

Try to search for a PostgreSQL database in RHEL using this command:

yum list postgre*
Loaded plugins: product-id, refresh-packagekit, search-disabled-repos, security, subscription-
: manager
Available Packages
postgresql.x86_64 8.4.20-7.el6 @rhel-6-workstation-rpms
postgresql-libs.x86_64 8.4.20-7.el6 @rhel-6-workstation-rpms
postgresql-server.x86_64 8.4.20-7.el6 @rhel-6-workstation-rpms
postgresql.i686 8.4.20-7.el6 rhel-6-workstation-rpms
postgresql-contrib.x86_64 8.4.20-7.el6 rhel-6-workstation-rpms
postgresql-devel.i686

Install the available package:

yum install postgresql-server.x86_64

This will install the PostgreSQL database and create a user called postgres. As this user, one can access PostgreSQL. The root user can change the password if required for this user with the following command:

passwd postgres

Now, switch to the postgres user. Then run the psql command.

su - postgres
psql

Create a schema activemq with username and password activemq. Also, provide this schema access to connect with user activemq.

postgres=# create ROLE activemq LOGIN PASSWORD 'activemq' SUPERUSER;
CREATE ROLE
postgres=#
postgres=# CREATE DATABASE activemq WITH OWNER = activemq;
CREATE DATABASE
postgres=#
postgres=# GRANT CONNECT ON DATABASE activemq TO activemq;
GRANT

We have to provide access to remote applications to connect to PostgreSQL. To open database port 5432 to the remote application, we will have to edit postgresql.conf and set listen_addresses to *.

[root@vm252-99 cpandey]# vi /var/lib/pgsql/data/postgresql.conf
listen_addresses='*'

To whitelist remote IPs to connect to the PostgreSQL server, we will have to edit pg_hba.conf.

[root@vm252-99 cpandey]# vi /var/lib/pgsql/data/pg_hba.conf

#all remote connection

host all all 0.0.0.0/0 md5

Stop and start the PostgreSQL server.

[root@vm252-99 cpandey]# service postgresql stop
Stopping postgresql service: [ OK ]
[root@vm252-99 cpandey]# service postgresql start
Starting postgresql service:

Now, we edit the broker and configure activemq.xml to have the following configuration:

<beans...>
	<broker... brokerName="testPostgre1"....>
----
----

		<persistenceAdapter>
			<jdbcPersistenceAdapter dataSource="#postgres-ds" lockKeepAlivePeriod="5000">
				<locker>
					<lease-database-locker lockAcquireSleepInterval="10000"/>
				</locker>
			</jdbcPersistenceAdapter>
		</persistenceAdapter>
----
----

	</broker>
	<bean id="postgres-ds" class="org.postgresql.ds.PGPoolingDataSource">
		<property name="url" value="jdbc:postgresql://10.74.252.99:5432/activemq"/>
		<property name="user" value="activemq"/>
		<property name="password" value="activemq"/>
		<property name="initialConnections" value="1"/>
		<property name="maxConnections" value="10"/>
	</bean>
----
----

</beans>

Some points to note in the step above:

  • Remember to set brokerName. It should be unique for each broker.
  • persistenceAdapter, referring to datasource #postgres-ds, is set with lease-database-locker within the broker XML tag.
  • The postgre-ds datasource is defined as a bean outside of the broker tag and within the beans tag.

Restart brokers to obtain the lock, then check the database.

[cpandey@vm252-99 ~]$ su - postgres
Password:
-bash-4.1$ psql
# connect to activemq schema
postgres=# \c activemq
# check tables
activemq=# \dt
List of relations
Schema | Name | Type | Owner
--------+---------------+-------+----------
public | activemq_acks | table | activemq
public | activemq_lock | table | activemq
public | activemq_msgs | table | activemq
(3 rows)
# run select query.
activemq=# select * from activemq_lock;
id | time | broker_name
----+---------------+--------------
1 | 1506947282760 | testPostgre1

Above, broker testPostgre1 has occupied the lock.

I hope this article helps you understand and set up JDBC persistence for ActiveMQ using the PostgreSQL database.

PostgreSQL Persistence (computer science)

Published at DZone with permission of Chandra Shekhar Pandey, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Distributed Rate Limiting in Java: A Deep Dive into Bucket4j + PostgreSQL
  • Data Storage and Indexing in PostgreSQL: Practical Guide With Examples and Performance Insights
  • Monorepo Development With React, Node.js, and PostgreSQL With Prisma and ClickHouse
  • Comparing Managed Postgres Options on The Azure Marketplace

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: