You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Bill Chen <bi...@iii.org.tw> on 2017/06/05 06:56:23 UTC

JDBC persistence for postgresql

Hi All,

I am using ActiveMQ 5.14.5 as MQTT broker, and I would like to use postgres
as database.

My configuration in activemq.xml:

<persistenceAdapter>
    <jdbcPersistenceAdapter dataDirectory="${activemq.base}/data"
dataSource="#postgres-ds>
        <adapter><postgresql-jdbc-adapter/></adapter>
    </jdbcPersistenceAdapter>
</persistenceAdapter>

<bean id="postgres-ds" class="org.postgresql.ds.PGPoolingDataSource"
destroy-method="close">
    <property name="serverName" value="192.168.15.2"/>
    <property name="databaseName" value="activemq"/>
    <property name="portNumber" value="5432"/>
    <property name="user" value="activemq"/>
    <property name="password" value="activemq"/>
    <property name="dataSourceName" value="postgres"/>
    <property name="initialConnections" value="1"/>
    <property name="maxConnections" value="10"/>
</bean>

When I start ActiveMQ, I check the tables(activemq_acks, activemq_lock,
activemq_msgs) has created in postgres.
But, no data persist to table after I publish message to subscriber.

Any hints would be appreciated.

Regards,

Bill



--
View this message in context: http://activemq.2283324.n4.nabble.com/JDBC-persistence-for-postgresql-tp4727004.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: JDBC persistence for postgresql

Posted by Bill Chen <bi...@iii.org.tw>.
Hi Tim, 

I found Message.setBooleanProperty() in javax.jms.Message, but I actually
used the Eclipse Paho MQTT client to publish message.
I have set the retained property in
org.eclipse.paho.client.mqttv3.MqttMessage, 
does it like to the ActiveMQ.Retain property as you mentioned?

Bill



--
View this message in context: http://activemq.2283324.n4.nabble.com/JDBC-persistence-for-postgresql-tp4727004p4727532.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: JDBC persistence for postgresql

Posted by Tim Bain <tb...@alumni.duke.edu>.
On Jun 7, 2017 4:14 AM, "Bill Chen" <bi...@iii.org.tw> wrote:

Tim,

I'm sorry that confused you about the reference link.
I'm doing the ActiveMQ way, and I have encountered some questions.

First, how to set the ActiveMQ.Retain property?


You call Message.setBooleanProperty().

Second, I try to add the RetainedMessageSubscriptionRecoveryPolicy in my
configuration, but that occurred exception when activemq start. The
configuration as follows:
<destinationPolicy>
  <policyMap>
    <policyEntries>
      <policyEntry topic=">" >
        <pendingMessageLimitStrategy>
          <constantPendingMessageLimitStrategy limit="1000"/>
        </pendingMessageLimitStrategy>

        <subscriptionRecoveryPolicy>
          <retainedMessageSubscriptionRecoveryPolicy/>
        </subscriptionRecoveryPolicy>
      </policyEntry>
    </policyEntries>
  </policyMap>
</destinationPolicy>


I think I may have led you astray on this one. Per
http://rockablogbaby.blogspot.com/2014/05/scalable-iot-integration-using-apache.html?m=1,
RetainedMessageSubscriptionRecoveryPolicy is always present in the broker,
and doesn't need to be configured explicitly. I'll update the wiki to
reflect that, when I have a chance.

Third, I have successfully received the message from the topic in the
previous test. But I find the subscriber change to that queue on the web
console now.


I don't understand what you're telling me. Are you saying that you switched
to using queues instead of topics and it worked?

I'm not sure what the cause is. The data in activemq_acks table

as follows:
<http://activemq.2283324.n4.nabble.com/file/n4727144/activemq_acks.png>

Bill



--
View this message in context: http://activemq.2283324.n4.nab
ble.com/JDBC-persistence-for-postgresql-tp4727004p4727144.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: JDBC persistence for postgresql

Posted by Bill Chen <bi...@iii.org.tw>.
Tim,

I'm sorry that confused you about the reference link.
I'm doing the ActiveMQ way, and I have encountered some questions.

First, how to set the ActiveMQ.Retain property?

Second, I try to add the RetainedMessageSubscriptionRecoveryPolicy in my
configuration, but that occurred exception when activemq start. The
configuration as follows:
<destinationPolicy>
  <policyMap>
    <policyEntries>
      <policyEntry topic=">" >
        <pendingMessageLimitStrategy>
          <constantPendingMessageLimitStrategy limit="1000"/>
        </pendingMessageLimitStrategy>

        <subscriptionRecoveryPolicy>
          <retainedMessageSubscriptionRecoveryPolicy/>
        </subscriptionRecoveryPolicy>
      </policyEntry>
    </policyEntries>
  </policyMap>
</destinationPolicy>

Third, I have successfully received the message from the topic in the
previous test. But I find the subscriber change to that queue on the web
console now. I'm not sure what the cause is. The data in activemq_acks table
as follows:
<http://activemq.2283324.n4.nabble.com/file/n4727144/activemq_acks.png> 

Bill



--
View this message in context: http://activemq.2283324.n4.nabble.com/JDBC-persistence-for-postgresql-tp4727004p4727144.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: JDBC persistence for postgresql

Posted by Tim Bain <tb...@alumni.duke.edu>.
Bill,

You've forwarded a link to documentation for an unrelated product, so I
want to make sure you're doing this the ActiveMQ way and not the IBM
MessageSight way. Are you saying that you configured
the RetainedMessageSubscriptionRecoveryPolicy subscription recovery policy
as described in http://activemq.apache.org/subscription-recovery-policy.html,
and that you've also set the ActiveMQ.Retain property to true on the
messages you're publishing?

Given that you're using a topic, you're right that you won't be able to see
the message in the web console. But do you have at least one consumer on
the topic? If so, does it receive the message as usual? If not, is the
behavior any different if you redo the test with a consumer attached?
Normal messages sent to a topic will just be discarded if there is no
consumer for them, and I'm not sure whether that is supposed to change with
retained messages.

Also, that web page doesn't specify whether retained messages are supposed
to survive a broker restart. If not, it would make sense for them to be
stored in the memory store, which would mean that the functionality might
be working even though the message isn't in the database. Have you tried
subscribing a retroactive consumer to see whether the message is delivered
to it?

Tim

On Jun 6, 2017 9:21 PM, "Bill Chen" <bi...@iii.org.tw> wrote:

> Hi, Tim
>
> I'm not sure the retained flag is the same as the persistent flag.
> About the retained flag as follows:
> https://www.ibm.com/support/knowledgecenter/en/SSCGGQ_1.0.
> 0/com.ibm.ism.doc/Overview/ov00033.html
>
> I publish to a message to a topic, not to a queue. So, I don't have any
> information in that queue on the web console. Is it the cause of no message
> in the database table?
>
> Bill
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.
> nabble.com/JDBC-persistence-for-postgresql-tp4727004p4727131.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: JDBC persistence for postgresql

Posted by Bill Chen <bi...@iii.org.tw>.
Hi, Tim

I'm not sure the retained flag is the same as the persistent flag.
About the retained flag as follows:
https://www.ibm.com/support/knowledgecenter/en/SSCGGQ_1.0.0/com.ibm.ism.doc/Overview/ov00033.html

I publish to a message to a topic, not to a queue. So, I don't have any
information in that queue on the web console. Is it the cause of no message
in the database table?

Bill



--
View this message in context: http://activemq.2283324.n4.nabble.com/JDBC-persistence-for-postgresql-tp4727004p4727131.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: JDBC persistence for postgresql

Posted by Tim Bain <tb...@alumni.duke.edu>.
What's the retained flag?

So to be sure I'm understanding correctly: you publish a message to the
queue (or are you publishing to a topic?), you do not consume it, and you
can see the message in that queue on the web console, but it's not in the
database table. Is that all correct? When you click on the message in the
web console, what is the value of the Persistence attribute?

Tim

On Jun 6, 2017 4:40 AM, "Bill Chen" <bi...@iii.org.tw> wrote:

> Thanks Tim.
>
> I have set the retained flag for message when producer publish.
> But the message still not stored in the activemq_msgs table.
> May I need to modify my configuration in activemq.xml?
>
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.
> nabble.com/JDBC-persistence-for-postgresql-tp4727004p4727073.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: JDBC persistence for postgresql

Posted by Bill Chen <bi...@iii.org.tw>.
Thanks Tim.

I have set the retained flag for message when producer publish.
But the message still not stored in the activemq_msgs table.
May I need to modify my configuration in activemq.xml?




--
View this message in context: http://activemq.2283324.n4.nabble.com/JDBC-persistence-for-postgresql-tp4727004p4727073.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: JDBC persistence for postgresql

Posted by Tim Bain <tb...@alumni.duke.edu>.
Each message your producer publishes has to have the persistent flag set,
otherwise the (non-persistent) message will be stored in the memory store.
Are you setting that flag when you publish your messages?

On Jun 5, 2017 1:11 AM, "Bill Chen" <bi...@iii.org.tw> wrote:

> Hi All,
>
> I am using ActiveMQ 5.14.5 as MQTT broker, and I would like to use postgres
> as database.
>
> My configuration in activemq.xml:
>
> <persistenceAdapter>
>     <jdbcPersistenceAdapter dataDirectory="${activemq.base}/data"
> dataSource="#postgres-ds>
>         <adapter><postgresql-jdbc-adapter/></adapter>
>     </jdbcPersistenceAdapter>
> </persistenceAdapter>
>
> <bean id="postgres-ds" class="org.postgresql.ds.PGPoolingDataSource"
> destroy-method="close">
>     <property name="serverName" value="192.168.15.2"/>
>     <property name="databaseName" value="activemq"/>
>     <property name="portNumber" value="5432"/>
>     <property name="user" value="activemq"/>
>     <property name="password" value="activemq"/>
>     <property name="dataSourceName" value="postgres"/>
>     <property name="initialConnections" value="1"/>
>     <property name="maxConnections" value="10"/>
> </bean>
>
> When I start ActiveMQ, I check the tables(activemq_acks, activemq_lock,
> activemq_msgs) has created in postgres.
> But, no data persist to table after I publish message to subscriber.
>
> Any hints would be appreciated.
>
> Regards,
>
> Bill
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.
> nabble.com/JDBC-persistence-for-postgresql-tp4727004.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>