Thanks, I've found the answer myself...
However, the problem in my code was simply that THE PERSISTENCE CONFIGURATION MUST BE DONE BEFORE ADDING THE CONNECTOR. That is, the call of setPersistence() method must be done before m_broker.addConnector("tcp://localhost:61616"); Could I create a page on your Confluence explaining this simple BUT NOT DOCUMENTED question? Providing also my very very simple example about how to configure a BrokerService with persistence on MySql DB? If the answer is yes, where can I append the page? I would put it in the FAQ section... Is there a test class about persistence configuration of a BrokerService? I looked for it in test folder of activemq-core project but I didn't find it. Best regards. Raffaele P.S.: Documentation should have the highest priority, especially in open projects very useful like this. Raffaele wrote: > > I'm sorry but I need more help to configure from Java an embedded > broker... > > In particular I 'm not able to set persitence in MySql, in fact when I > launch my example (that you can found after this message) I cannot see > messages in tables... > And, if I delete the three tables, my code don't reacreate them... > > Javadoc of Brokerservice is poor and there isn't a page that explains the > configurations steps from directly Java code... > > In my example I start a broker and create a consumer that send messages to > a queue... > > The main question is "Why do the messages are stored on db"? > The code is the following: > import javax.jms.JMSException; > > import org.apache.activemq.broker.BrokerService; > import org.apache.activemq.memory.UsageManager; > import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter; > import org.apache.activemq.store.jdbc.adapter.MySqlJDBCAdapter; > import org.apache.commons.dbcp.BasicDataSource; > > > > import webrainbow.util.debug.WrCheck; > > public class EmbeddedBroker { > > private BrokerService m_broker; > > public EmbeddedBroker() { > m_broker = new BrokerService(); > > // Some configurations > m_broker.setBrokerName("EmbeddedBroker_localhost"); > m_broker.setUseJmx(false); > m_broker.setPersistent(true); > > // Setto il memoryManager > UsageManager um = new UsageManager(); > // Setto il limite in byte > um.setLimit(20000000); > m_broker.setMemoryManager(um); > > > // Add connector > try { > m_broker.addConnector("tcp://localhost:61616"); > } catch (Exception e) { > WrCheck.logError(e); > } > } > > > public void go() { > setPersistence(); > > try { > m_broker.start(); > } catch (Exception e) { > WrCheck.logError(e); > } > > startDeliveryToQueue(); > } > > > private void setPersistence() { > // Create a JDBC persistence adapter and set it to use the > Oracle > Adapter. > JDBCPersistenceAdapter jdbcPersistence = new > JDBCPersistenceAdapter(); > > jdbcPersistence.setAdapter(new MySqlJDBCAdapter()); > > // Create a basic datasource > (org.apache.commons.dbcp.BasicDataSource) > and > // set the JDBC properties on it. > > BasicDataSource bds = new BasicDataSource(); > > > bds.setUrl("jdbc:mysql://localhost/activemq?relaxAutoCommit=true"); > > bds.setDriverClassName("com.mysql.jdbc.Driver"); > > bds.setUsername("root"); > > bds.setPassword(""); > > bds.setPoolPreparedStatements(true); > > // Set the datasource on the JDBC persistence adapter. > jdbcPersistence.setDataSource(bds); > > m_broker.setPersistenceAdapter(jdbcPersistence); > } > > > private void startDeliveryToQueue() { > QueueProducer producer = null; > try { > producer = new QueueProducer("tcp://localhost:61616", > "ARCHIVER_QUEUE"); > } catch (JMSException e1) { > WrCheck.logWarn(e1); > } > > for(;;) { > try { > String time = > String.valueOf(System.currentTimeMillis()); > WrCheck.logInfo("Sending queue message --> <" + time + > ">"); > producer.sendMessage(time); > > } catch (JMSException ex) { > WrCheck.logWarn(ex); > > try { > WrCheck.logInfo("WebServerSimulator going to > sleep..."); > Thread.sleep(10 * 1000); > > producer.restart(); > } > catch (Exception e) { > WrCheck.logWarn(e); > } > } > catch (Exception exc) { > WrCheck.logFatal(exc); > } > > try { > Thread.sleep((long) (Math.random() * 3000)); > } catch (InterruptedException e) { > WrCheck.logWarn(e); > } > } > } > > > public static void main(String[] args) throws Exception { > EmbeddedBroker eb = new EmbeddedBroker(); > eb.go(); > } > } > > Best regards. > -- View this message in context: http://www.nabble.com/Embedded-Broker---configuration-via-Java-tf3888599s2354.html#a11057175 Sent from the ActiveMQ - User mailing list archive at Nabble.com.