Skip to content

Commit 4eaa975

Browse files
author
dlavoie
committed
Initial commit
0 parents  commit 4eaa975

File tree

23 files changed

+653
-0
lines changed

23 files changed

+653
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
.classpath
3+
.project
4+
.settings
5+
target

pom.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<artifactId>spring-boot-starter-parent</artifactId>
7+
<groupId>org.springframework.boot</groupId>
8+
<version>1.1.4.RELEASE</version>
9+
</parent>
10+
11+
<groupId>com.cspinformatique.redis.message</groupId>
12+
<artifactId>redis-message</artifactId>
13+
14+
<version>0.0.1-SNAPSHOT</version>
15+
16+
<packaging>pom</packaging>
17+
18+
<modules>
19+
<module>redis-message-core</module>
20+
<module>redis-message-client</module>
21+
<module>redis-message-server</module>
22+
</modules>
23+
24+
<dependencyManagement>
25+
<dependencies>
26+
<dependency>
27+
<groupId>com.cspinformatique.redis.message</groupId>
28+
<artifactId>redis-message-core</artifactId>
29+
<version>0.0.1-SNAPSHOT</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.cspinformatique</groupId>
33+
<artifactId>commons</artifactId>
34+
<version>0.1.0</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.jredis</groupId>
38+
<artifactId>jredis</artifactId>
39+
<version>1.0 RC2</version>
40+
</dependency>
41+
</dependencies>
42+
</dependencyManagement>
43+
</project>

redis-message-client/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>com.cspinformatique.redis.message</groupId>
5+
<artifactId>redis-message</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
</parent>
8+
<artifactId>redis-message-client</artifactId>
9+
<dependencies>
10+
<dependency>
11+
<groupId>com.cspinformatique.redis.message</groupId>
12+
<artifactId>redis-message-core</artifactId>
13+
</dependency>
14+
</dependencies>
15+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.cspinformatique.redis.message.client.service;
2+
3+
import com.cspinformatique.redis.core.entity.Message;
4+
5+
public interface MessageService{
6+
public Message consumeMessageFromQueue();
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.cspinformatique.redis.message.client.service.impl;
2+
3+
import java.net.InetAddress;
4+
import java.net.UnknownHostException;
5+
6+
import javax.annotation.PostConstruct;
7+
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.stereotype.Service;
10+
11+
import com.cspinformatique.redis.core.entity.Consumer;
12+
import com.cspinformatique.redis.core.entity.Message;
13+
import com.cspinformatique.redis.core.repository.MessageRepository;
14+
import com.cspinformatique.redis.core.service.ConsumerService;
15+
16+
import com.cspinformatique.redis.message.client.service.MessageService;
17+
18+
@Service
19+
public class MessageServiceImpl implements MessageService {
20+
@Autowired private ConsumerService consumerService;
21+
@Autowired private MessageRepository messageRepository;
22+
23+
private Consumer consumer;
24+
25+
@PostConstruct
26+
public void init(){
27+
try {
28+
this.consumer = consumerService.getConsumer(InetAddress.getLocalHost().getHostName(), 0);
29+
} catch (UnknownHostException unknownHostEx) {
30+
throw new RuntimeException(unknownHostEx);
31+
}
32+
}
33+
34+
public Message consumeMessageFromQueue(){
35+
Long messageId = this.messageRepository.consumeMessageFromQueue(consumer.getId());
36+
37+
if(messageId != null){
38+
return messageRepository.getMessage(messageId);
39+
}
40+
41+
return null;
42+
}
43+
}

redis-message-core/pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>com.cspinformatique.redis.message</groupId>
6+
<artifactId>redis-message</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
</parent>
9+
<artifactId>redis-message-core</artifactId>
10+
<dependencies>
11+
<dependency>
12+
<groupId>com.cspinformatique</groupId>
13+
<artifactId>commons</artifactId>
14+
</dependency>
15+
<dependency>
16+
<groupId>org.springframework</groupId>
17+
<artifactId>spring-context</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.springframework.data</groupId>
21+
<artifactId>spring-data-redis</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>redis.clients</groupId>
25+
<artifactId>jedis</artifactId>
26+
</dependency>
27+
</dependencies>
28+
</project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.cspinformatique.redis.core.entity;
2+
3+
public class Consumer {
4+
private long id;
5+
private String hostname;
6+
private int port;
7+
8+
public Consumer(){
9+
10+
}
11+
12+
public Consumer(long id, String hostname, int port) {
13+
this.id = id;
14+
this.hostname = hostname;
15+
this.port = port;
16+
}
17+
18+
public long getId() {
19+
return id;
20+
}
21+
22+
public void setId(long id) {
23+
this.id = id;
24+
}
25+
26+
public String getHostname() {
27+
return hostname;
28+
}
29+
30+
public void setHostname(String hostname) {
31+
this.hostname = hostname;
32+
}
33+
34+
public int getPort() {
35+
return port;
36+
}
37+
38+
public void setPort(int port) {
39+
this.port = port;
40+
}
41+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.cspinformatique.redis.core.entity;
2+
3+
public class Message {
4+
private long id;
5+
private String message;
6+
7+
public Message(){
8+
9+
}
10+
11+
public Message(Long id, String message) {
12+
this.id = id;
13+
this.message = message;
14+
}
15+
16+
public long getId() {
17+
return id;
18+
}
19+
20+
public void setId(long id) {
21+
this.id = id;
22+
}
23+
24+
public String getMessage() {
25+
return message;
26+
}
27+
28+
public void setMessage(String message) {
29+
this.message = message;
30+
}
31+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.cspinformatique.redis.core.exception;
2+
3+
public class MessageNotFoundException extends RuntimeException {
4+
private static final long serialVersionUID = -5403757382697773520L;
5+
6+
private long messageId;
7+
8+
public MessageNotFoundException(long messageId){
9+
this.messageId = messageId;
10+
}
11+
12+
public long getMessageId() {
13+
return messageId;
14+
}
15+
16+
public void setMessageId(long messageId) {
17+
this.messageId = messageId;
18+
}
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.cspinformatique.redis.core.repository;
2+
3+
import java.util.List;
4+
5+
import com.cspinformatique.redis.core.entity.Consumer;
6+
7+
public interface ConsumerRepository {
8+
public void addConsumer(Consumer consumer);
9+
10+
public void deleteConsumer(long consumerId);
11+
12+
public long generateConsumerId();
13+
14+
public Consumer getConsumer(long consumerId);
15+
16+
public List<Consumer> getConsumers();
17+
}

0 commit comments

Comments
 (0)