avatarVikas Taank

Summary

The web content provides an advanced discussion on Senior Java Lead interview questions, focusing on microservices architecture, communication methods between microservices, WebSocket technology, and interview preparation tips.

Abstract

The article titled "InterSenior Java Lead Interview Questions (Advanced)-07" delves into the concept of microservices, illustrating their characteristics and the various ways they can communicate with each other, such as REST, asynchronous messaging, and event-driven methods. It also explains WebSockets, a technology used for real-time bidirectional communication between clients and servers, providing code examples for both WebSocket server and client implementations in Java. The author expresses gratitude for reader engagement and feedback, emphasizing the continuous improvement of their content and commitment to expanding the list of interview questions for comprehensive preparation.

Opinions

  • The author values reader feedback and appreciation, acknowledging the impact of community support on their content creation.
  • There is an appreciation for the interest shown by readers and friends, which motivates the author to enhance the quality and scope of their articles.
  • The author is dedicated to providing an exhaustive list of interview questions to aid in interview preparation, indicating a commitment to being a valuable resource for Java professionals.
  • The inclusion of a serene winter landscape image suggests the author's belief in the importance of relaxation and balance, possibly implying that learning and well-being should go hand in hand.

InterSenior Java Lead Interview Questions.(Advanced)-07

What are micro services?

Micro Services Characteristics

Could you describe the ways micro services can communicate with one another?

Microservices can communicate using several methods as described below.

Micro Service Communications

For more details on micro service inter communications please refer to my article:

Could you please explain Web Sockets and how are they used.

Web Socket Server.

import javax.websocket.OnMessage;
import javax.websocket.server.ServerEndpoint;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpointConfig;
@ServerEndpoint("/demo")
public class WebSocketServer {
    @OnMessage
    public String onMessage(String message) {
        return "Server echoed: " + message;
    }
    public static void main(String[] args) {
        // Server setup code goes here
        // Typically, you would use an external server like Tomcat or Jetty to run this WebSocket server
    }
}

WebSocket Client

import javax.websocket.ContainerProvider;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import java.net.URI;

public class WebSocketClient {

    @javax.websocket.ClientEndpoint
    public static class ClientEndpoint {

        @OnMessage
        public void onMessage(String message) {
            System.out.println("Received message: " + message);
        }
    }

    public static void main(String[] args) {
        try {
            WebSocketContainer container = ContainerProvider.getWebSocketContainer();
            String uri = "ws://localhost:8080/demo"; // Replace with your server URI
            Session session = container.connectToServer(ClientEndpoint.class, URI.create(uri));

            session.getBasicRemote().sendText("Hello WebSocket");
            // Wait to ensure the message is received before closing
            Thread.sleep(1000);

            session.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Thanks a lot for reading my content and helping me to write better and better by providing constant feedbacks and your claps. I really appreciate as single clap and all the people and my friends are showing interest in my content. I am really greatful. I will keep extending this list for more exhaustive interview preparation. Thanks for sharing.

A beautiful winter landscape for relaxation.

Interview
Interview Questions
Interview Preparation
Microservices
Java
Recommended from ReadMedium