This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 973
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ramazansakin/master
docker-compose & refactoring
Showing
38 changed files
with
522 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
/.project | ||
*.idea | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
FROM openjdk | ||
FROM openjdk:8-jdk-alpine | ||
MAINTAINER Piotr Minkowski <[email protected]> | ||
MAINTAINER Ramazan Sakin <[email protected]> | ||
ADD target/account-service.jar account-service.jar | ||
ENTRYPOINT ["java", "-jar", "/account-service.jar"] | ||
EXPOSE 2222 | ||
EXPOSE 2222 | ||
ENTRYPOINT ["java", "-jar", "/account-service.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 15 additions & 15 deletions
30
...in/microservices/account/Application.java → ...es/account/AccountServiceApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package pl.piomin.microservices.account; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
|
||
@SpringBootApplication | ||
@EnableDiscoveryClient | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
|
||
} | ||
package pl.piomin.microservices.account; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
|
||
@SpringBootApplication | ||
@EnableDiscoveryClient | ||
public class AccountServiceApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(AccountServiceApplication.class, args); | ||
} | ||
|
||
} |
115 changes: 75 additions & 40 deletions
115
account-service/src/main/java/pl/piomin/microservices/account/api/Api.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,85 @@ | ||
package pl.piomin.microservices.account.api; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
import pl.piomin.microservices.account.exceptions.AccountNotFoundException; | ||
import pl.piomin.microservices.account.model.Account; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.logging.Logger; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import pl.piomin.microservices.account.model.Account; | ||
|
||
@RestController | ||
@Slf4j | ||
public class Api { | ||
|
||
private List<Account> accounts; | ||
|
||
protected Logger logger = Logger.getLogger(Api.class.getName()); | ||
|
||
public Api() { | ||
accounts = new ArrayList<>(); | ||
accounts.add(new Account(1, 1, "111111")); | ||
accounts.add(new Account(2, 2, "222222")); | ||
accounts.add(new Account(3, 3, "333333")); | ||
accounts.add(new Account(4, 4, "444444")); | ||
accounts.add(new Account(5, 1, "555555")); | ||
accounts.add(new Account(6, 2, "666666")); | ||
accounts.add(new Account(7, 2, "777777")); | ||
} | ||
|
||
@RequestMapping("/accounts/{number}") | ||
public Account findByNumber(@PathVariable("number") String number) { | ||
logger.info(String.format("Account.findByNumber(%s)", number)); | ||
return accounts.stream().filter(it -> it.getNumber().equals(number)).findFirst().get(); | ||
} | ||
|
||
@RequestMapping("/accounts/customer/{customer}") | ||
public List<Account> findByCustomer(@PathVariable("customer") Integer customerId) { | ||
logger.info(String.format("Account.findByCustomer(%s)", customerId)); | ||
return accounts.stream().filter(it -> it.getCustomerId().intValue()==customerId.intValue()).collect(Collectors.toList()); | ||
} | ||
|
||
@RequestMapping("/accounts") | ||
public List<Account> findAll() { | ||
logger.info("Account.findAll()"); | ||
return accounts; | ||
} | ||
|
||
private List<Account> accounts; | ||
|
||
public Api() { | ||
accounts = new ArrayList<>(); | ||
accounts.add(new Account(1, 1, "111111")); | ||
accounts.add(new Account(2, 2, "222222")); | ||
accounts.add(new Account(3, 3, "333333")); | ||
accounts.add(new Account(4, 4, "444444")); | ||
accounts.add(new Account(5, 1, "555555")); | ||
accounts.add(new Account(6, 2, "666666")); | ||
accounts.add(new Account(7, 2, "777777")); | ||
} | ||
|
||
@RequestMapping(method = RequestMethod.GET, value = "/number/{number}") | ||
public Account findByNumber(@PathVariable("number") String number) throws AccountNotFoundException { | ||
log.info(String.format("Account.findByNumber(%s)", number)); | ||
return accounts.stream() | ||
.filter(it -> it.getNumber().equals(number)) | ||
.findFirst() | ||
.orElseThrow(() -> new AccountNotFoundException("number : " + number)); | ||
} | ||
|
||
@RequestMapping(method = RequestMethod.GET, value = "/customer/{customer}") | ||
public List<Account> findByCustomer(@PathVariable("customer") Integer customerId) { | ||
log.info(String.format("Account.findByCustomer(%s)", customerId)); | ||
return accounts.stream() | ||
.filter(it -> it.getCustomerId().intValue() == customerId.intValue()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@RequestMapping(method = RequestMethod.GET, value = "") | ||
public List<Account> findAll() { | ||
log.info("Account.findAll()"); | ||
return accounts; | ||
} | ||
|
||
@RequestMapping(method = RequestMethod.GET, value = "/{id}") | ||
public Account findById(@PathVariable Integer id) throws AccountNotFoundException { | ||
log.info("Account.findAll()"); | ||
return accounts.stream() | ||
.filter(it -> it.getId().equals(id)) | ||
.findFirst() | ||
.orElseThrow(() -> new AccountNotFoundException("id : " + id)); | ||
} | ||
|
||
@RequestMapping(method = RequestMethod.POST, value = "") | ||
public Account createNewAccount(@RequestBody Account account) { | ||
log.info("Account.createNewAccount()"); | ||
if (account.getId() != null) { | ||
return null; | ||
} | ||
int size = accounts.size(); | ||
account.setId(size + 1); | ||
accounts.add(account); | ||
return account; | ||
} | ||
|
||
@RequestMapping(method = RequestMethod.DELETE, value = "/{id}") | ||
public boolean deleteAccount(@PathVariable Integer id) { | ||
log.info("Account.deleteAccount()"); | ||
try { | ||
Account byId = findById(id); | ||
accounts.remove(byId); | ||
} catch (AccountNotFoundException e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} |
34 changes: 17 additions & 17 deletions
34
...ervices/account/AccountConfiguration.java → .../account/config/AccountConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
package pl.piomin.microservices.account; | ||
|
||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ComponentScan("pl.piomin.microservices.account") | ||
public class AccountConfiguration { | ||
|
||
@Bean | ||
public AlwaysSampler defaultSampler() { | ||
return new AlwaysSampler(); | ||
} | ||
|
||
} | ||
package pl.piomin.microservices.account.config; | ||
|
||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ComponentScan("pl.piomin.microservices.account") | ||
public class AccountConfiguration { | ||
|
||
@Bean | ||
public AlwaysSampler defaultSampler() { | ||
return new AlwaysSampler(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 10 additions & 37 deletions
47
account-service/src/main/java/pl/piomin/microservices/account/model/Account.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,16 @@ | ||
package pl.piomin.microservices.account.model; | ||
|
||
public class Account { | ||
|
||
private Integer id; | ||
private Integer customerId; | ||
private String number; | ||
|
||
public Account() { | ||
|
||
} | ||
|
||
public Account(Integer id, Integer customerId, String number) { | ||
this.id = id; | ||
this.customerId = customerId; | ||
this.number = number; | ||
} | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public Integer getCustomerId() { | ||
return customerId; | ||
} | ||
|
||
public void setCustomerId(Integer customerId) { | ||
this.customerId = customerId; | ||
} | ||
|
||
public String getNumber() { | ||
return number; | ||
} | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Account { | ||
|
||
public void setNumber(String number) { | ||
this.number = number; | ||
} | ||
private Integer id; | ||
private Integer customerId; | ||
private String number; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
FROM openjdk | ||
FROM openjdk:8-jdk-alpine | ||
MAINTAINER Piotr Minkowski <[email protected]> | ||
MAINTAINER Ramazan Sakin <[email protected]> | ||
ADD target/customer-service.jar customer-service.jar | ||
EXPOSE 3333 | ||
ENTRYPOINT ["java", "-jar", "/customer-service.jar"] | ||
EXPOSE 3333 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 17 additions & 17 deletions
34
...n/microservices/customer/Application.java → .../customer/CustomerServiceApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
package pl.piomin.microservices.customer; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
import org.springframework.cloud.netflix.feign.EnableFeignClients; | ||
|
||
@SpringBootApplication | ||
@EnableDiscoveryClient | ||
@EnableFeignClients | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
|
||
} | ||
package pl.piomin.microservices.customer; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
import org.springframework.cloud.netflix.feign.EnableFeignClients; | ||
|
||
@SpringBootApplication | ||
@EnableDiscoveryClient | ||
@EnableFeignClients | ||
public class CustomerServiceApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(CustomerServiceApplication.class, args); | ||
} | ||
|
||
} |
Oops, something went wrong.