Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service-Oriented Architecture pattern (#2937) #2946

Closed

Conversation

romannimets
Copy link
Contributor

What problem does this PR solve?

Related issue: Service-Oriented Architecture pattern (#2937)
Introduces the Service-Oriented Architecture (SOA) pattern to enhance modular service interaction.

This PR addresses the need to implement Service-Oriented Architecture (SOA) to improve the interaction between modular services within the application. The SOA pattern facilitates loose coupling, service abstraction, reusability, interoperability, scalability, statelessness, discoverability, and security, enhancing the overall architecture of the system.

The main points considered when implementing SOA are:

  • Loose Coupling: Services should operate independently without knowledge of other services.
  • Service Abstraction: Services hide complexity behind a clear interface.
  • Service Reusability: Services are designed for reuse across different parts of the application.
  • Interoperability: Services operate with other services using standard protocols.
  • Scalability: Services can be scaled independently to handle increasing loads.
  • Statelessness: Services handle each request independently, increasing reliability.
  • Discoverability: Services can be easily discovered through standard mechanisms.
  • Security: Robust security measures are implemented to secure communication and data access.

Implementing SOA involves setting up a service registry, defining service interfaces, ensuring security protocols, and creating middleware for efficient service communication. Each service functions as a discrete unit of functionality, facilitating a flexible and adaptable software environment.

public class ServiceRegistry {
public static final Map<String, Object> registry = new HashMap<>();

public static void registerService(String serviceName, Object serviceInstance) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object limits type safety.

we can do something like that:

public static void registerService(String serviceName, T serviceInstance) {
registry.put(serviceName, serviceInstance);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot! Did this, hope it looks good enough


private String getWeatherGreeting() {
WeatherCondition currentWeather = weatherService.getCurrentWeather();
switch (currentWeather) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch expressions can make this cleaner

Something like that:

return switch (currentWeather) {
case SUNNY -> "What a good sunny day";
case RAINY -> "What a rainy day";
...
...
default -> "Hello, and hope you have a great day despite the weather";
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all class as comment?

.defaultSuccessUrl("/home/greeting", true)
.permitAll()
)
.logout(LogoutConfigurer::permitAll);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LogoutConfigurer::permitAll -- > ensure that only the logged-in user can initiate their own logout


@RestController
@RequestMapping("home")
public class GreetingController {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can consider a @ControllerAdvice to handle errors in controllers? or we can handle it try / catch if something goes wrong?

updated ServiceRegistry to use generic type T
use of ConcurrentHashMap in ServiceRegistry
Copy link

stale bot commented Jul 22, 2024

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the status: stale issues and pull requests that have not had recent interaction label Jul 22, 2024
Copy link

stale bot commented Sep 6, 2024

Closed due to inactivity. Thank you for your contributions.

@stale stale bot closed this Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: stale issues and pull requests that have not had recent interaction
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants