Unable to see queue information or messages in activemq webconsole - mysql

I'm trying to configure Activemq with MySql. Everything seems to have been configured properly as i am able to send and receive messages through code. But I'm not able to see any queue or messages information in the Activemq Web Console.
below is my activemq config . Any help is apprciated.
Thank you!
Activemq.xml:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>file:${activemq.conf}/credentials.properties</value>
</property>
</bean>
<broker useJmx="false" brokerName="jdbcBroker" xmlns="http://activemq.apache.org/schema/core">
<persistenceAdapter>
<jdbcPersistenceAdapter dataDirectory="${activemq.base}/activemq-data" dataSource="#mysql-ds"/>
</persistenceAdapter>
<transportConnectors>
<transportConnector name="default" uri="tcp://0.0.0.0:61616"/>
</transportConnectors>
</broker>
<bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>
<property name="username" value="admin"/>
<property name="password" value="root"/>
<property name="maxActive" value="200"/>
<property name="poolPreparedStatements" value="true"/>
</bean>
<import resource="jetty.xml"/>
</beans>

As the WebConsole is using JMX to retrieve data, you should try to remove useJmx="false" from your broker configuration.

Related

Play 2.3 JPA Hibernate MySQL Pooling/Connection Error

I'm developing a Play 2.3 Application with JPA/Hibernate and use a Heroku/ClearDB.com MySQL Database for this but after the application connects successfully to the DB I get following error:
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection to jdbc:mysql://eu-cdbr-west-01.cleardb.com:3306/heroku_b7ea7b2d2972532 Sleeping for 1000ms and trying again. Attempts left: 10. Exception: null.Message:User 'badd25925bdd5f' has exceeded the 'max_user_connections' resource (current value: 10)
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: User 'badd25925bdd5f' has exceeded the 'max_user_connections' resource (current value: 10)
I tried almost everything I saw on other posts but nothing helped... I think it has to do with pooling...?
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://eu-cdbr-west-01.cleardb.com:3306/heroku_b7ea7b2d2972532?reconnect=true"/>
<property name="javax.persistence.jdbc.user" value="badd25925bdd5f"/>
<property name="javax.persistence.jdbc.password" value="XXX"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.c3p0.min_size" value="2"/>
<property name="hibernate.c3p0.max_size" value="9"/>
<property name="hibernate.c3p0.timeout" value="300"/>
<property name="hibernate.c3p0.max_statements" value="50"/>
<property name="hibernate.c3p0.idle_test_period" value="3000"/>
</properties>
</persistence-unit>
</persistence>
application.conf (relevant part)
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://eu-cdbr-west-01.cleardb.com:3306/heroku_b7ea7b2d2972532"
db.default.user="badd25925bdd5f"
db.default.password="XXX"
jpa.default=defaultPersistenceUnit
Thanks a lot for your help!
I don't know about using Hibernate, but with Ebean the connection pool by default is managed by BoneCP. Try to configure it in your application.conf:
# Max connections = partitionCount * maxConnPerPartition
db.default.partitionCount=2
db.default.maxConnectionsPerPartition=5
or in your persistence.xml:
<property name="bonecp.partitionCount" value="2" />
<property name="bonecp.maxConnectionsPerPartition" value="5" />
The error says that you are using more connections then your plan .So you can
Either upgrade you db plans see https://addons.heroku.com/cleardb#ignite
or
You can try scaling down your aplication see https://devcenter.heroku.com/articles/scaling
Solution to this problem (for Play 2.3) was to add the play-hikaricp library to the application.

Tomcat creates new database session on every start + mysql

I am developing a web application and my stack is Mysql+ hibernate+ spring. I noticed that each time i start my tomcat a new database session is created.
my application.context xml has the following configuration
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
<property name="driverClassName" value="${database.driverClassName}"/>
<property name="url" value="${database.url}"/>
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="1800000"/>
<property name="numTestsPerEvictionRun" value="3"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
<property name="validationQuery" value="SELECT 1"/>
<property name="maxActive" value="15" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="60" />
<property name="logAbandoned" value="true" />
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
Any help is much appreciated
There could be two possibilities.
Either your application is executing queries on start up. This can be verified by turning on hibernate/spring logging.
The default minIdle/initialSize connection property of the connection pool is 1. Initial size refers to the initial number of connections created when the pool is started while minIdle refers minimum number of connections that can remain idle in the pool, without extra ones being created

Junit is successful when use session.save but not inserting data in MySQL database tables eventhough i tried with flush the session as well

Simple DAO Layer wiht applicationContext.xml please find below my applicationContect.xml
please help me to understand why my Junit says successful but data are not inserting into the db.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:component-scan base-package="com.VideoRental.*" />
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/test"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
<bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="annotatedClasses">
<list>
<value>com.VideoRental.domain.Category</value>
<value>com.VideoRental.domain.Customer</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.hbm2ddl.import_files">import.sql</prop>
<prop key="connection.autocommit">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.connection.autocommit">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
</beans>
By default, #Transactional tests will roll-back all changes when the test method completes. So even if the test passes, the changes are only valid for the current running Transaction. To persist your changes, you need to commit the transaction.
Check out the example on this SO question.
You can replace #Transactional with transactionTemplate to commit the transaction prior to finishing a test.
If you are using #Transactional annotation driven in your project, you can simply set
#TransactionConfiguration(defaultRollback = false, transactionManager = "YourTransactionManager")
in your test case will work perfectly. I've researched for days and worked good finally in my local test cases, hopefully this will helps you too.

persistence exception on database connection using glassfish

I'm new to glass-fish & persistence and while trying to run a query on MySQL database in my machine i get the following error:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: No database selected
Error Code: 1046
before running the server i made sure that the server configuration are done using this guide : mysql site manual for using connector with glassfish, and configured my persistence.xml like this:
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="StudentRecipieWebsite" transaction-type="RESOURCE_LOCAL">
<non-jta-data-source>jdbc/mySql</non-jta-data-source>
<class>il.musehunter.studentRecipes.dbModel.Image</class>
<class>il.musehunter.studentRecipes.dbModel.Ingrediant</class>
<class>il.musehunter.studentRecipes.dbModel.Recipe</class>
<class>il.musehunter.studentRecipes.dbModel.User</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/recipes_data"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="moshe1475"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
</properties>
</persistence-unit>
I'm really new to this and does not have a clue to what i should do next so any help would be very appreciated.
edit:
adding part of the domain.xml from my glassfish server :
<applications>
<application context-root="/StudentRecipieWebsite" location="${com.sun.aas.instanceRootURI}/applications/StudentRecipieWebsite/" name="StudentRecipieWebsite" object-type="user">
<property name="appLocation" value="${com.sun.aas.instanceRootURI}/applications/__internal/StudentRecipieWebsite/StudentRecipieWebsite.war"></property>
<property name="org.glassfish.ejb.container.application_unique_id" value="89812698949156864"></property>
<property name="org.glassfish.persistence.app_name_property" value="StudentRecipieWebsite"></property>
<property name="defaultAppName" value="StudentRecipieWebsite"></property>
<module name="StudentRecipieWebsite">
<engine sniffer="ejb"></engine>
<engine sniffer="security"></engine>
<engine sniffer="jpa"></engine>
<engine sniffer="web"></engine>
</module>
</application>
and:
<resources>
<jdbc-resource pool-name="__TimerPool" jndi-name="jdbc/__TimerPool" object-type="system-admin"></jdbc-resource>
<jdbc-resource pool-name="DerbyPool" jndi-name="jdbc/__default"></jdbc-resource>
<jdbc-connection-pool datasource-classname="org.apache.derby.jdbc.EmbeddedXADataSource" res-type="javax.sql.XADataSource" name="__TimerPool">
<property name="databaseName" value="${com.sun.aas.instanceRoot}/lib/databases/ejbtimer"></property>
<property name="connectionAttributes" value=";create=true"></property>
</jdbc-connection-pool>
<jdbc-connection-pool is-isolation-level-guaranteed="false" datasource-classname="org.apache.derby.jdbc.ClientDataSource" res-type="javax.sql.DataSource" name="DerbyPool">
<property name="PortNumber" value="1527"></property>
<property name="Password" value="APP"></property>
<property name="User" value="APP"></property>
<property name="serverName" value="localhost"></property>
<property name="DatabaseName" value="sun-appserv-samples"></property>
<property name="connectionAttributes" value=";create=true"></property>
</jdbc-connection-pool>
<jdbc-connection-pool datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" res-type="javax.sql.DataSource" name="MySQLConnPool">
<property name="portNumber" value="3306"></property>
<property name="databaseName" value="recipes_data"></property>
<property name="serverName" value="localhost"></property>
<property name="user" value="root"></property>
<property name="password" value="moshe1475"></property>
<property name="URL" value="jdbc:mysql://:3306/"></property>
</jdbc-connection-pool>
<jdbc-resource pool-name="MySQLConnPool" description="" jndi-name="jdbc/mySql"></jdbc-resource></resources>
My first guess is that the connection URL in the data source definition is not quite right because "No database selected Error Code: 1046" is a MySQL error.
You do not need to configure the data source in persistence.xml if you have already defined a data source in your application server (which is the common way). Can you post the data source definition from your $GLASSFISH_HOME/glassfish/domains/$GLASSFISH_DOMAIN/config/domain.xml?
This is an example persistence.xml I took from an project of mine (more or less from the Netbeans template) that might help you:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="MyPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/sample</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
Good luck!
Answering to the comment:
You need to add the database name to the URL:
<property name="URL" value="jdbc:mysql://nameOrIPOfYourServerOrLocalhost:3306/nameOfYourDatabase"></property>
That should resolve the problem.

Database Connections Aren't Closing

I'm using spring 3.0 (jdbcTemplate), Tomcat, MySQL and C3p0 to handle my database activities. I'm using both jdbctemplate and simplejdbctemplate which will take care of creating and closing connections, statements, resultsets etc. I'm using C3p0 for connection pooling however the connections are remaining open and eventually the app will run out of connections.
Here is the configuration of my data source:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" >
<property name="driverClass" value="${jdbc.driverClassName}"></property>
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="initialPoolSize" value="5"></property>
<property name="maxPoolSize" value="100"/>
<property name="minPoolSize" value="5"/>
<property name="maxIdleTime" value="30"/>
<property name="maxIdleTimeExcessConnections" value="30"/>
<property name="maxConnectionAge" value="30"/>
<property name="checkoutTimeout" value="100"/>
<property name="maxStatements" value="50"></property>
<property name="automaticTestTable" value="C3P0_TEST_TABLE"></property>
<property name="testConnectionOnCheckin" value="true"></property>
<property name="idleConnectionTestPeriod" value="30"></property>
</bean>
I'm also using TransactionManagement provided by spring - here is the configuration of that:
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
Here is the rest of the datasource configuration:
<bean id="simpleJdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
<constructor-arg><ref bean="dataSource"/></constructor-arg>
</bean>
<bean id="userDAO" class="com.Test.dao.UserDAOImpl">
<property name="jdbcTemplate"><ref bean="jdbcTemplate"/></property>
</bean>
Finally here is a method where I update records into a database:
#Transactional(readOnly=false)
public void updateBenchMarkCumulative(List<BenchMarkCumulative> bmCumulativeList)
{
List<Object[]> parameters = new ArrayList<Object[]>();
for(BenchMarkCumulative bmCumulative : bmCumulativeList)
{
parameters.add(new Object[]{bmCumulative.getCumulativeAmt(), bmCumulative.getPkBenchMarkCumulative()});
}
this.simpleJdbcTemplate.batchUpdate(UPDATE_BENCHMARK_CUMULATIVE, parameters);
}
Is there something I'm doing wrong in my configuration or am I missing something that needs to be added to the configuration or coding?
Here is the exception being thrown:
INFO [http-8080-1] (AbstractPoolBackedDataSource.java510) - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ java.beans.IntrospectionException: java.lang.reflect.InvocationTargetException [numThreadsAwaitingCheckoutDefaultUser] ]
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"
Thank you in advance.
Keith
I would agree with axtavt. I was in a similar situation, and there were couple places I was manually opening connections but not closing them (stored procedure calls for iSeries). Please verify if you have that kind of spots.