Skip to content

Commit

Permalink
More test of README
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennifer Hickey committed Apr 24, 2012
1 parent eabb971 commit a0d7c94
Showing 1 changed file with 134 additions and 38 deletions.
172 changes: 134 additions & 38 deletions README.md
Expand Up @@ -36,7 +36,7 @@ System.out.println("Mongo available at host: " + service.getHost() + " and port:
```

## Connecting to services using Java API
If you don't care to use the cloud namespace, you can still take advantage of the [Java API](http://cf-runtime-api.cloudfoundry.com) to make programmatic service connections. See the javadoc for all extensions of [AbstractServiceCreator]. The service creators for Mongo and Redis require Spring Data. The RabbitServiceCreator requires Spring AMQP. Service creators for MySQL and PostgreSQL will create a Commons DBCP DataSource if the libraries are present, else they will attempt to create a Tomcat DataSource.
If you don't care to use the cloud namespace, you can still take advantage of the [Java API](http://cf-runtime-api.cloudfoundry.com) to make programmatic service connections. See the javadoc for all extensions of AbstractServiceCreator. The service creators for Mongo and Redis require Spring Data. The RabbitServiceCreator requires Spring AMQP. Service creators for MySQL and PostgreSQL will create a Commons DBCP DataSource if the libraries are present, else they will attempt to create a Tomcat DataSource.

Here is an example that creates a connection to a Mongo service named "my-mongo":
```java
Expand Down Expand Up @@ -86,7 +86,7 @@ A simple example DataSource configuration to be injected into a JdbcTemplate wou

There are sub-elements that can be used to configure specific connections and pool settings. The \<cloud:data-source\> namespace element supports the most commonly used configuration options via the \<cloud:connection\> and \<cloud:pool\> sub-elements. The supported options are explained below:

##### <cloud:connection> options
##### \<cloud:connection\> options

<html>
<table>
Expand All @@ -103,24 +103,63 @@ There are sub-elements that can be used to configure specific connections and po
</table>
</html>

<cloud:pool> options
Namespace attribute Description Type Default
pool-size Either the maximum number of connections in the pool or a range specifying minimum and maximum size separated by a dash. int Uses the default settings of the Apache Commons Pool which are 0 for min and 8 for max size
max-wait-time The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception. -1 indicates unlimited wait. int Uses the default setting of the Apache Commons Pool which is unlimited (-1)
##### \<cloud:pool\> options

#### <cloud:mongo-db-factory>
The <cloud:mongo-db-factory> element provides a convenient way to configure the MongoDB connection factory for your Spring application.
<html>
<table>
<tr>
<th>Namespace attribute</th>
<th>Description</th>
<th>Type</th>
<th>Default</th>
</tr>
<tr>
<td>pool-size</td>
<td>Either the maximum number of connections in the pool or a range specifying minimum and maximum size separated by a dash.</td>
<td>int</td>
<td>Uses the default settings of the Apache Commons Pool which are 0 for min and 8 for max size</td>
<tr>
<td>max-wait-time</td>
<td>The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception. -1 indicates unlimited wait.</td>
<td>int</td>
<td>Uses the default setting of the Apache Commons Pool which is unlimited (-1)</td>
</tr>
</table>
</html>

#### \<cloud:mongo-db-factory\>
The \<cloud:mongo-db-factory\> element provides a convenient way to configure the MongoDB connection factory for your Spring application.
Basic attributes:
id – defaults to service name
service-name – only needed if you have multiple MongoDB services bound to the app
write-concern – the WriteConcern to use for all DB connections created (NONE, NORMAL, SAFE, FSYNC_SAFE). If this is not specified then no WriteConcern will be set for the DB connections and all writes will default to NORMAL

The values for the write-concern attribute correspond to the values available in the com.mongodb.WriteConcern class.
Value Description
NONE No exceptions are raised, even for network issues
NORMAL Exceptions are raised for network issues, but not server errors
SAFE Exceptions are raised for network issues, and server errors; waits on a server for the write operation
FSYNC_SAFE Exceptions are raised for network issues, and server errors and the write operation waits for the server to flush the data to disk

<html>
<table>
<tr>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>NONE</td>
<td>No exceptions are raised, even for network issues</td>
</tr>
<tr>
<td>NORMAL</td>
<td>Exceptions are raised for network issues, but not server errors</td>
</tr>
<tr>
<td>SAFE</td>
<td>Exceptions are raised for network issues, and server errors; waits on a server for the write operation</td>
</tr>
<tr>
<td>FSYNC_SAFE</td>
<td>Exceptions are raised for network issues, and server errors and the write operation waits for the server to flush the data to disk</td>
</tr>
</table>
</html>

A simple example MongoDbFactory configuration to be injected into a MongoTemplate would look like this, with the only attribute used specifying the id of the mongoDbFactory bean.
```xml
Expand All @@ -131,15 +170,35 @@ A simple example MongoDbFactory configuration to be injected into a MongoTemplat
</bean>
```

There are some advanced configuration attributes that are available using the <cloud:mongo-options> sub-element and they are listed below.
<cloud:mongo-options>
Namespace attribute Description Type Default
connections-per-host The maximum number of connections allowed per host for the Mongo instance. Those connections will be kept in a pool when idle. Once the pool is exhausted, any operation requiring a connection will block waiting for an available connection. int The Mongo driver has a default of 10
max-wait-time The maximum wait time in ms that a thread may wait for a connection to become available. int The Mongo driver has a default of 120000
There are some advanced configuration attributes that are available using the \<cloud:mongo-options\> sub-element and they are listed below.

##### \<cloud:mongo-options\>

#### <cloud:redis-connection-factory>
The <cloud:redis-connection-factory> element provides a convenient way to configure the Redis connection factory for your Spring application.
<html>
<table>
<tr>
<th>Namespace attribute</th>
<th>Description</th>
<th>Type</th>
<th>Default</th>
</tr>
<tr>
<td>connections-per-host</td>
<td>The maximum number of connections allowed per host for the Mongo instance. Those connections will be kept in a pool when idle. Once the pool is exhausted, any operation requiring a connection will block waiting for an available connection.</td>
<td>int</td>
<td>The Mongo driver has a default of 10</td>
</tr>
<tr>
<td>max-wait-time</td>
<td>The maximum wait time in ms that a thread may wait for a connection to become available.</td>
<td>int</td>
<td>The Mongo driver has a default of 120000</td>
</tr>
</table>
</html>

#### \<cloud:redis-connection-factory\>
The \<cloud:redis-connection-factory\> element provides a convenient way to configure the Redis connection factory for your Spring application.
Available attributes:
id – defaults to service name
service-name – only needed if you have multiple Redis services bound to the app
Expand All @@ -152,14 +211,35 @@ A simple example RedisConnectionFactory configuration to be injected into a Redi
<property name="connection-factory" ref="redisConnectionFactory"/>
</bean>
```
The advanced configuration attributes that are available via the <cloud:pool> sub-element are listed below.
<cloud:pool> options
Namespace attribute Description Type Default
pool-size Either the maximum number of connections in the pool or a range specifying minimum and maximum size separated by a dash. int Uses the default settings of the Apache Commons Pool which are 0 for min and 8 for max size
max-wait-time The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception. int Uses the default setting of the Apache Commons Pool which is unlimited (-1)

#### <cloud:rabbit-connection-factory>
The <cloud:rabbit-connection-factory> element provides a convenient way to configure the RabbitMQ connection factory for your Spring application.
The advanced configuration attributes that are available via the \<cloud:pool\> sub-element are listed below.

##### \<cloud:pool\> options

<html>
<table>
<tr>
<th>Namespace attribute</th>
<th>Description</th>
<th>Type</th>
<th>Default</th>
</tr>
<tr>
<td>pool-size</td>
<td>Either the maximum number of connections in the pool or a range specifying minimum and maximum size separated by a dash.</td>
<td>int</td>
<td>Uses the default settings of the Apache Commons Pool which are 0 for min and 8 for max size</td>
</tr>
<tr>
<td>max-wait-time</td>
<td>The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception.</td>
<td>int</td>
<td>Uses the default setting of the Apache Commons Pool which is unlimited (-1)</td>
</tr>
</table>
</html>

#### \<cloud:rabbit-connection-factory\>
The \<cloud:rabbit-connection-factory\> element provides a convenient way to configure the RabbitMQ connection factory for your Spring application.
Available attributes:
id – defaults to service name
service-name – only needed if you have multiple RabbitMQ services bound to the app
Expand All @@ -171,14 +251,30 @@ A simple example RabbitConnectionFactory configuration to be injected into a Rab
<rabbit:template id="rabbitTemplate"
connection-factory="rabbitConnectionFactory" />
```
The advanced configuration attributes that are available via the <cloud:rabbit-options> are listed below.
<cloud:rabbit-options>
Namespace attribute Description Type Default
channel-cache-size The size of the channel cache. int The default is 1

#### <cloud:service-scan>
The <cloud:service-scan> element scans all services bound to the application and creates a bean of an appropriate type for each. You can think of this element as a cloud extension of <context:component-scan> in core Spring, which scans the classpath for beans with certain annotations and creates a bean for each. The <cloud:service-scan> is especially useful during the initial phases of application development, where you want immediate access to service beans without adding a <cloud> element for each new service bound.
Once you include a <cloud:service-scan> element in application context, then in your Java code, simply add @Autowired dependencies for each bound service:
The advanced configuration attributes that are available via the \<cloud:rabbit-options\> are listed below.

##### \<cloud:rabbit-options\>

<html>
<table>
<tr>
<th>Namespace attribute</th>
<th>Description</th>
<th>Type</th>
<th>Default</th>
</tr>
<tr>
<td>channel-cache-size</td>
<td>The size of the channel cache.</td>
<td>int</td>
<td>The default is 1</td>
</tr>
</table>
</html>

#### \<cloud:service-scan\>
The \<cloud:service-scan\> element scans all services bound to the application and creates a bean of an appropriate type for each. You can think of this element as a cloud extension of \<context:component-scan\> in core Spring, which scans the classpath for beans with certain annotations and creates a bean for each. The \<cloud:service-scan\> is especially useful during the initial phases of application development, where you want immediate access to service beans without adding a \<cloud\> element for each new service bound.
Once you include a \<cloud:service-scan\> element in application context, then in your Java code, simply add @Autowired dependencies for each bound service:
```java
@Autowired DataSource dataSource;
@Autowired ConnectionFactory rabbitConnectionFactory;
Expand All @@ -194,8 +290,8 @@ the @Qualifier to specify the service name (each automatically created bean is n
```
Here, the inventoryDataSource bean will be bound to the inventory-db service and the pricingDataSource bean will be bound to the pricing-db service.

#### <cloud:properties>
#### \<cloud:properties\>
Available attributes:
id – the name of the Properties bean
The <cloud:properties> element exposes basic information about services that can be consumed with Spring’s property placeholder support. The properties exposed match those automatically enabled for a Spring 3.1 application.
The \<cloud:properties\> element exposes basic information about services that can be consumed with Spring’s property placeholder support. The properties exposed match those automatically enabled for a Spring 3.1 application.

0 comments on commit a0d7c94

Please sign in to comment.