I want to initialize multiple connection pools at context startup by reading connection parameters from a database table. Basically I want to address following two things
Read connection properties from database not the properties file.
Their are multiple connection pool(rows in db) details.
So my question is How can I iterate over list of rows returned by database in spring-context file and create multiple data-source objects and store them (Lets say in a map) with a unique key?
Databse table structure are somewhat like following:
+--------------+----------------+---------------+
| DBSERVERNAME | DBDRIVERCLASS | DBMINPOOLSIZE |
+--------------+----------------+---------------+
| Server1 | Mysql-Driver | 10 |
| Server2 | Oracle-Driver | 20 |
| Server3 | DB2-Driver | 10 |
+--------------+----------------+---------------+
Let me know if more details are needed. Thanks.
Related
Is there any difference between those 2 in terms of execution time?
collectionReference.add(testObject)
.addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
#Override
public void onSuccess(DocumentReference documentReference) {
collectionReference.add(testObject2);
}
})
And
collectionReference.add(testObject);
collectionReference.add(testObject2);
In the first case second adding will be executed after first one is finished, is the same thing happening in second case? Is the second adding queried and is waiting for first to finish, or are they running in parallel?
Yes, there will be a difference between the execution time of these two.
In the first case you're waiting for the first write to be completed on the server, before sending the second write to the server. In a diagram:
Client Server
| |
|---- Send document to write ----->|
| |
| |
|<----- Response from server ------|
|---- Send document to write ----->|
| |
| |
|<----- Response from server ------|
| |
In the second case, the second write is sent to the server right after the first write was sent.
Client Server
| |
|---- Send document to write ----->|
|---- Send document to write ----->|
| |
| |
| |
|<----- Response from server ------|
|<----- Response from server ------|
| |
The difference in performance between these two is the latency of the connection between you and the server.
Note that this is just the theoretical difference, and likely there are many more factors influencing the performance.
I am learning rabbitMq and and now I want to know how to wath queue content.
First of all I want to day that I googled this question and know about command
python rabbitmqadmin list queues
I have written 2 separated applications.
sender:
#Autowired
private AmqpTemplate template;
...
for (int i = 0; i < 100; i++) {
template.convertAndSend("queue1", "message_" + i);
}
receiver:
#RabbitListener(queues = "queue1")
public void listenQueue1(String message, #Header(AmqpHeaders.DELIVERY_TAG) long tag) {
logger.info("Got message:[" + message + "]");
}
If I run these applications together - I see messages on receiver side.
To see messages in the queue I decided to stop receiver and run sender
I run sender
execute python rabbitmqadmin list queues
and see following result:
+-----------------+----------+
| name | messages |
+-----------------+----------+
| query-example-6 | |
| queue1 | |
| queue2 | |
| queue3 | |
| queue4 | |
| queue5 | |
| queue6 | |
| queue7 | |
| queue8 | |
| queue9 | |
+-----------------+----------+
3.Then I run receiver and see logs that receiver accepted messages
Can you clarify reason why I can't see messages in console?
How to see queue messages content.
I am not familiar with rabbitmq.
maybe the message is "unacknowledged"?
e.g. I found my queue has a message:
$ rabbitmqadmin list queues name node messages
+----------------------------+----------------+----------+
| name | node | messages |
+----------------------------+----------------+----------+
| my_queue_name | rabbit#xx-2 | 1 |
but when I run "get" command to show its content, rabbitmq tells me "there's no item"
so, I query it with this command:
$ rabbitmqadmin list queues name node messages messages_ready messages_unacknowledged
+----------------------------+----------------+----------+----------------+-------------------------+
| name | node | messages | messages_ready | messages_unacknowledged |
+----------------------------+----------------+----------+----------------+-------------------------+
| my_queue_name | rabbit#xxxxx-2 | 1 | 0 | 1 |
+----------------------------+----------------+----------+----------------+-------------------------+
I don't know why. just restart the rabbitmq server and everything seems goes fine.
I'm working on an application which is based on PostgreSQL 9, hibernate 4.3.5.Final, c3p0, Tomcat 7 and JDK 7.
Here is the c3p0 configuration:
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
After few hours of utilization, the application is hanging. All screen are frozen because it seemed like no new transaction to the database could be opened.
I did a kill -3 on the tomcat 7 process (there is a single app deployed) to see where all the threads are locked. Here's a part of the output:
"ajp-bio-8127-exec-274" daemon prio=10 tid=0x0000000001365000 nid=0x257b in Object.wait() [0x0000000045242000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1414)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:606)
- locked <0x000000078567cb70> (a com.mchange.v2.resourcepool.BasicResourcePool)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:526)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectio
It's the same for all the http requests processes. So all requests are waiting indefinitly for an available connection in the pool.
We had a look at the postgres to see that 20 connections were opened (20 is the pool max size):
foobar=# select datname, usename, client_port, query from pg_stat_activity where usename='foobar';
datname | usename | client_port | query
---------+---------+-------------+----------
foobar | foobar | 52992 | ROLLBACK
foobar | foobar | 52993 | ROLLBACK
foobar | foobar | 52991 | ROLLBACK
foobar | foobar | 52994 | ROLLBACK
foobar | foobar | 52995 | ROLLBACK
foobar | foobar | 36398 | ROLLBACK
foobar | foobar | 36399 | ROLLBACK
foobar | foobar | 36400 | ROLLBACK
foobar | foobar | 51766 | ROLLBACK
foobar | foobar | 56689 | ROLLBACK
foobar | foobar | 56690 | ROLLBACK
foobar | foobar | 39582 | ROLLBACK
foobar | foobar | 39581 | ROLLBACK
foobar | foobar | 39583 | ROLLBACK
foobar | foobar | 39590 | ROLLBACK
foobar | foobar | 39592 | ROLLBACK
foobar | foobar | 39591 | ROLLBACK
foobar | foobar | 41799 | ROLLBACK
foobar | foobar | 36105 | ROLLBACK
foobar | foobar | 36103 | ROLLBACK
(20 rows)
So, we configured the pool logs to DEBUG, and we can see statements like theses:
2014/07/09 05:24:40 DEBUG (BasicResourcePool.java:1747) trace trace com.mchange.v2.resourcepool.BasicResourcePool#12c39c9e [managed: 19, unused: 4, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection#4fc04747)
They show that the managed connexion number grows slowly until managed: 20 and usused: 0 this final state remains stable and the application is frozen because all the threads are expecting a connection to be available from the pool.
It's a web application and we use the session in request pattern so the connection are closed properly after each request is processed (in a finally statement). There is no such thing like an ERROR or WARN in the application logs.
How can I know what did I do wrong ?
Well evidently those queries are getting blocked without being released. It could be that you are getting some exception or something which you are not seeing, because the query is marked as ROLLBACK, and for some reason the thread is hanging waiting for the query to finish or something of that sort. Without seeing the code its difficult to say exactly.
What you could do is wait for this to happen again and then get a full thread dump. This should give you full details of where each thread is hanging, so you could see what the 20 connections are waiting on.
You can use jstack for this, which comes with the JDK.
You could also enable JMX on Tomcat and connect to it using jconsole or jvisualvm to see in real time what the threads are doing.
It looks like your application runs out of available pooled connections. A transaction is marked as rollback only if an exception was thrown. If you can't see any exception it might be because you don't properly handle them, like logging any exception with an ERROR threshold.
You need to check the db log as well, maybe you find what causes all those transactions to rollback.
I am trying to implement some data flow as follows
______________ _____________ _____________
| myecom.com | submit | myecom.com | add additional | payment.com |
| product.html |------------>| process.php |----------------->| pay.php |
| myform | form data | | data & submit | |
-------------- ------------- -------------
|
______________ |
| myecom.com |<--------------------------------
| receiver.php | success or failure info
--------------
An ecommerce site receive some info from user
Submit the info to an internal processor
The internal processor processes the data
The processed data along with some additional data is submitted to an external processor
The external processor sends back some success/failure report
My goal is to perform step 4 without informing the user what data is being submitted to external processor. In another word, I want to POST some data to the external processor from the internal processor.
FYI, simply cURL will not do as it does not redirect. The page must redirect to payment.com/pay.php. Also, it need to to be PHP specific, any technology like Java, etc. will do. I am considering storing the data in session using cURL and then javascript redirect. But is there any other ways?
Thanks a lot for your time
Khalid
How about doing it like this instead?
______________ _____________ _____________
| myecom.com | (1) submit | myecom.com | (2) add additional | payment.com |
| product.html |------------>| process.php |-------------------->| pay.php |
| myform | form data | | data & submit | |
-------------- ------------- -------------
| ^ |
| | |
(4) redirect | ---------------------------------
| (3) success or failure info
v
______________
| myecom.com |
| receiver.php |
--------------
Explanation: Your internal processor sends the user data plus the additional data to the external processor. Since it's your server that makes the POST request to the external processor, the user never sees the request and thus cannot see the data that is being sent.
I'm not a PHP programmer, but a quick Google query on "PHP post request" revealed these two links, see if they help you:
How do I send a POST request with PHP?
Three Ways to Make a POST Request from PHP
Assuming I have single host RabbitMQ server and settings like below:
.--------------.
.->| EX fanout |
.-----------.--' | "monitoring" |
| EX fanout | '--------------' .----.
| "common" |--. .-----------. .->| Q1 |
'-----------' '->| EX direct |--q1--' '----'
| "queues" |--q2--. .----.
'-----------' '->| Q2 |
'----'
When I send message to exchange "common" with routing key "q1" - is it guaranteed that message reach Q1 queue?
I want to make sure such message wont get stuck somewhere between exchanges or between exchange and queue.