Skip to content

Commit 0009818

Browse files
authored
Merge pull request #8 from mkopylec/feature
Feature
2 parents 64b05db + 6222d28 commit 0009818

File tree

61 files changed

+1416
-781
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1416
-781
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
*.iml
33
gradle.properties
44
.gradle
5-
build
5+
build
6+
classes

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
language: java
22
jdk:
3-
- oraclejdk7
3+
- oraclejdk8
44
before_install:
55
- sudo apt-get -qq update
66
- sudo apt-get install -y libssl1.0.0
7-
- sudo wget http://packages.couchbase.com/releases/4.0.0/couchbase-server-community_4.0.0-ubuntu12.04_amd64.deb
8-
- sudo dpkg -i couchbase-server-community_4.0.0-ubuntu12.04_amd64.deb
7+
- sudo wget http://packages.couchbase.com/releases/4.1.1/couchbase-server-community_4.1.1-ubuntu12.04_amd64.deb
8+
- sudo dpkg -i couchbase-server-community_4.1.1-ubuntu12.04_amd64.deb
99
- sleep 10
1010
- sudo /opt/couchbase/bin/couchbase-cli cluster-init -c localhost:8091 -u Administrator -p password --cluster-ramsize=256 --service=data,index,query
1111
- sudo /opt/couchbase/bin/couchbase-cli bucket-create -c localhost:8091 -u Administrator -p password --bucket=default --bucket-ramsize=256 --bucket-replica=1

README.md

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,26 @@ The project is based on:
99

1010
The project supports only Couchbase 4 and higher versions. For more information about Couchbase click [here](http://www.couchbase.com/).
1111

12+
## Migrating from 1.x.x to 2.x.x
13+
14+
- remove `@EnableCouchbaseHttpSession` annotation
15+
- replace `session-couchbase.persistent.couchbase` properties with `spring.couchbase` in the _application.yml_ file
16+
1217
## Installing
1318

1419
```gradle
1520
repositories {
1621
mavenCentral()
1722
}
1823
dependencies {
19-
compile 'com.github.mkopylec:session-couchbase-spring-boot-starter:1.2.2'
24+
compile 'com.github.mkopylec:session-couchbase-spring-boot-starter:2.0.0'
2025
}
2126
```
2227

2328
## How to use
24-
Enable Couchbase backed HTTP session using `@EnableCouchbaseHttpSession`:
29+
Create a Spring Boot web application:
2530

2631
```java
27-
@EnableCouchbaseHttpSession
2832
@SpringBootApplication
2933
public class Application {
3034

@@ -40,7 +44,7 @@ Simply use `HttpSession` interface to control HTTP session. For example:
4044
@Controller
4145
public class SessionController {
4246

43-
@RequestMapping("uri")
47+
@GetMapping("uri")
4448
public void doSomething(HttpSession session) {
4549
...
4650
}
@@ -50,37 +54,60 @@ public class SessionController {
5054
The starter can be used in 2 different modes:
5155

5256
### Couchbase backed persistence usage
53-
Configure Couchbase connection in _application.yml_ file:
57+
Configure Couchbase connection in _application.yml_ file using Session Couchbase and Spring Data Couchbase properties:
5458

5559
```yaml
56-
session-couchbase.persistent:
57-
namespace: <application_namespace>
58-
couchbase:
59-
hosts: <list_of_couchbase_cluster_hosts>
60-
bucket-name: <couchbase_bucket_name>
61-
password: <couchbase_bucket_password>
60+
session-couchbase:
61+
application-namespace: <application_namespace>
62+
63+
spring.couchbase:
64+
bootstrap-hosts: <list_of_couchbase_cluster_hosts>
65+
bucket:
66+
name: <couchbase_bucket_name>
67+
password: <couchbase_bucket_password>
6268
```
6369
64-
Optionally you can override default Couchbase client settings by creating `CouchbaseEnvironment` bean:
70+
For full list of supported Spring Data Couchbase properties see [here](http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html).
6571
66-
```java
67-
...
68-
@Primary
69-
@Bean(destroyMethod = "shutdown", name = "couchbaseEnv")
70-
public CouchbaseEnvironment couchbaseEnvironment() {
71-
...
72-
}
72+
Using Couchbase backed HTTP session you can share session among multiple web applications in a distributed system.
73+
The session will not be destroyed when the web applications will be shut down.
74+
75+
#### Retrying
76+
By default there is only one attempt to query Couchbase.
77+
It is possible to retry the query operation when an error occurs.
78+
The number of retries can be controlled in _application.yml_ file:
79+
80+
```yaml
81+
session-couchbase.persistent.retry.max-attempts: <number of attempts>
7382
```
7483
75-
##### Additional info
76-
Using Couchbase backed HTTP session you can share session among multiple web applications.
77-
The session will not be destroyed when the web applications will be shut down.
84+
The concurrent modification errors: `DML Error, possible causes include CAS mismatch or concurrent modificationFailed to perform update` can be avoided by increasing the number of maximum attempts.
7885

79-
You can access session attributes in 2 ways:
86+
### In-memory usage
87+
Enable in-memory mode in _application.yml_ file:
88+
89+
```yaml
90+
session-couchbase.in-memory.enabled: true
91+
```
92+
93+
Using in-memory HTTP session you can not share session among multiple web applications in a distributed.
94+
The session is visible only within a single web application instance and will be destroyed when the web application will be shut down.
95+
96+
The mode is useful for integration tests when you don't want to communicate with the real Couchbase server instance.
97+
98+
## Namespaces
99+
The starter supports HTTP session namespaces.
100+
Each web application in a distributed system has one application namespace under which the session attributes are stored.
101+
Every web application can also access global session attributes which are visible across the whole distributed system.
102+
Namespaces prevent conflicts in attributes names between different web applications in the system.
103+
Two web applications can have the same namespace and therefore access the same session attributes.
104+
If two web applications have different namespaces they cannot access each others session attributes.
105+
106+
You can access session attributes in 2 ways, using:
80107
- _application namespace_ - attributes are visible only to instances of the same web application within a distributed system
81108
- _global namespace_ - attributes are visible to all instances of all web applications within a distributed system
82109

83-
To access application namespace just pass an attribute name:
110+
To access application namespace attribute just pass an attribute name:
84111

85112
```java
86113
...
@@ -93,7 +120,7 @@ public void doSomething(HttpSession session) {
93120
}
94121
```
95122

96-
To access global attributes create an attribute name using `CouchbaseSession.globalAttributeName(...)` method:
123+
To access global attribute create an attribute name using `CouchbaseSession.globalAttributeName(...)` method:
97124

98125
```java
99126
...
@@ -108,34 +135,18 @@ public void doSomething(HttpSession session) {
108135

109136
When changing HTTP session ID every attribute is copied to the new session, no matter what namespace it belongs.
110137

111-
### In-memory usage
112-
Enable in-memory mode in _application.yml_ file:
113-
114-
```yaml
115-
session-couchbase.in-memory.enabled: true
116-
```
117-
118-
##### Additional info
119-
Using in-memory HTTP session you can not share session among multiple web applications.
120-
The session is visible only within a single web application instance and will be destroyed when the web application will be shut down.
121-
122-
There are no namespaces in the in-memory mode.
123-
124-
The mode is useful for integration tests when you don't want to communicate with the real Couchbase server instance.
125-
126138
## Configuration properties list
127139

128140
```yaml
129141
session-couchbase:
130142
timeout-in-seconds: 1800 # HTTP session timeout.
143+
application-namespace: # HTTP session application namespace under which session data must be stored.
144+
principal-sessions:
145+
enabled: false # Flag for enabling and disabling finding HTTP sessions by principal. Can significantly decrease application performance when enabled.
131146
persistent:
132-
namespace: # HTTP session application namespace under which session data must be stored.
133-
couchbase:
134-
hosts: localhost # Couchbase cluster hosts.
135-
bucket-name: default # Couchbase bucket name where session data must be stored.
136-
password: # Couchbase bucket password.
137-
principal-sessions:
138-
enabled: false # Flag for enabling and disabling finding HTTP sessions by principal. Can significantly decrease application performance when enabled.
147+
query-consistency: REQUEST_PLUS # N1QL query scan consistency.
148+
retry:
149+
max-attempts: 1 # Maximum number of attempts to repeat a query to Couchbase when error occurs.
139150
in-memory:
140151
enabled: false # Flag for enabling and disabling in-memory mode.
141152
```

build.gradle

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
id 'com.github.kt3k.coveralls' version '2.6.3'
77
id 'maven'
88
id 'signing'
9-
id 'pl.allegro.tech.build.axion-release' version '1.3.3'
9+
id 'pl.allegro.tech.build.axion-release' version '1.4.1'
1010
}
1111

1212
scmVersion {
@@ -19,29 +19,34 @@ group 'com.github.mkopylec'
1919
archivesBaseName = name
2020
version scmVersion.version
2121

22-
sourceCompatibility = 1.7
23-
targetCompatibility = 1.7
22+
sourceCompatibility = 1.8
23+
targetCompatibility = 1.8
2424

2525
repositories {
2626
mavenCentral()
2727
}
2828

29+
ext.springBootVersion = '1.4.2.RELEASE'
30+
2931
dependencies {
3032

31-
compile group: 'org.springframework.boot', name: 'spring-boot-starter', version: '1.4.0.RELEASE'
32-
compile('org.springframework.data:spring-data-couchbase:2.1.2.RELEASE') {
33+
compile group: 'org.springframework.boot', name: 'spring-boot-starter', version: springBootVersion
34+
compile("org.springframework.boot:spring-boot-starter-data-couchbase:$springBootVersion") {
3335
exclude group: 'org.springframework', module: 'spring-web'
3436
}
3537
compile group: 'org.springframework.session', name: 'spring-session', version: '1.2.2.RELEASE'
38+
compile group: 'org.springframework.retry', name: 'spring-retry', version: '1.1.4.RELEASE'
3639
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
37-
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.1-1'
40+
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.4'
3841
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
42+
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
3943

40-
compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '1.4.0.RELEASE', optional
44+
compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: springBootVersion, optional
4145

42-
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '1.4.0.RELEASE'
43-
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.4.0.RELEASE'
44-
testCompile group: 'org.spockframework', name: 'spock-spring', version: '1.0-groovy-2.4'
46+
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion
47+
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
48+
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-undertow', version: springBootVersion
49+
testCompile group: 'org.spockframework', name: 'spock-spring', version: '1.1-groovy-2.4-rc-3'
4550
}
4651

4752
configurations {

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-bin.zip

src/main/java/com/github/mkopylec/sessioncouchbase/EnableCouchbaseHttpSession.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)