MQ-related interview questions

If you have written your resume MQ, then the interviewer usually asks the following questions, at least I was often asked in the interview, so to sum up today, there is something wrong place to look to bear with me:

First, the first question, why use MQ?

If you have not thought about this problem, so that you will be just a simple MQ technology with a coder, not a programmer will think independently, if the interviewer asked this question, you did not answer it, then you the first impression will certainly be poor.

First, why use MQ?

(1) decoupling: If multiple modules or systems, calling each other very complicated to maintain up more trouble, but this call are not synchronous call, you can use MQ into this business.

(2) Asynchronous: this is well understood, such a user operation log maintenance can not synchronize, save response time.

(3) Clipping: At its peak, when the amount reached 5,000 requests per second system, the MySQL request call is 5000, MySQL requests under normal circumstances probably around 2000, then at the peak of the time, the database is defeated, and that the system is not available. At this time, the introduction of MQ, add MQ in front of the system A, MQ user request First, consumption of the system A 2000 per second data from the MQ, this would put the requested number 5000. The request becomes acceptable MySQL, and can ensure The system does not hang up, you can continue to provide services. MQ where the data can be slowly consumed it.

Second, the use of MQ have any problems?

Remember that a problem can be reduced by one increase.

(1) reduce the availability of the system (2) increases the complexity of the system

Third, how the selection MQ?

If you asked this question, the interviewer main difference is whether you want to see the selection would be more architecture meets business needs.

characteristic ActiveMQ RabbitMQ RocketMQ Kafka
Stand-alone Throughput Ten thousand Ten thousand One hundred thousand One hundred thousand
topic affect the number of throughput  -  -  topic can reach hundreds, thousands of levels, there will be a lesser extent decreased throughput  topic from tens to hundreds of times the throughput could drop significantly
 Timeliness  Millisecond  Microsecond  Millisecond  Millisecond
 Availability  high  high  Very high, distributed architecture  Very high, distributed architecture
 Message reliability  Have a lower probability of data loss  -  After parameter optimization configuration, it can do 0 loss  After optimizing the configuration parameters, the message is lost can be done 0
 Support functions  perfect  Concurrent capacity is very strong, very good performance, low latency  MQ function more perfect, or distributed, scalability  Function is relatively simple, the main support simple MQ function, real-time computing and large data log collection in the field is large-scale use, is the de facto standard
 Summarizes the advantages and disadvantages  Very mature and powerful; occasionally there will be a lower probability of message loss; not active in the community  Very good performance, low latency; functional; provide management interface; the community is more active; lower throughput; the use of open source erlang reading is not convenient;  The interface is easy to use; high-throughput; easy distributed expansion; the community is fairly active; proven dual 11  MQ less functional; high throughput; distributed architecture; there may be duplicate messages consumption issues; real-time computing is mainly used big data and log collection;

 personal suggestion:

Small and medium sized companies, technology in general, consider using RabbitMQ;
large companies, infrastructure, strong R & D capabilities, is a good choice with RocketMQ
real-time calculation, log collection: use kafka;

Fourth, how to ensure the MQ high availability?

RabbitMQ is more representative, because it is based on a master-slave do high availability. With his example, review the following modes on their own.

rabbitmq has three modes: stand-alone mode, normal mode clustering, mirroring the cluster mode .

Fifth, how to ensure that the consumer will not be repeated?

Unreasonable consumer queue, there will be a mechanism to inform the consumer, such as:

RabbitMQ provides a mechanism ACK acknowledgment message,

rocketMQ return a success flag CONSUME_SUCCESS

 (1) For example, do you get this message insert the database. It would be easy to give this message to make a unique primary key, even if the situation repeated consumption occurs, it will lead to a primary key conflict, to avoid the database appear dirty data.
 (2) As another example, do you get the news operation set the redis, it would be easy, not solve, because you set several times whether the results are the same, even if the power had set the operation and other operations.
 (3) If the above two cases is not enough, the big move. Prepare a third-party media, do consumer records. In redis example, a global id assigned to the message, as long as the message consumer through the <id, message> redis written in the form of KV. Before consumers start spending it, go redis there is no consumption record query can be.

Sixth, how to ensure reliable transmission of consumption?

 

Each MQ must lose data from the producer, consumer queue loss of data, loss of consumer data to answer the three levels

(1) loss of data producers

To rabbitMQ for example, rabbitMQ provides transaction and confirm model to ensure that producers do not lose data, transaction mechanisms, before sending the message, open transactions (channel.txSelect ()), an exception after sending the message, the transaction is rolled back (channel.txRollback ()), sent successfully commit the transaction (channel.txCommit ()).

In this way above the throughput will decrease, and therefore should be used on the production model confirm the majority.

Once entering confirm channel mode, all messages are posted on the channel is assigned a unique ID (starting at 1), the incoming messages such as queues, RabbitMQ immediately sends an ACK to the producer, which contains unique message ID , which makes the producers know that the message has reached the message queue. If the message queue is not able to process the message, it will send a NACK to the producer for a retry operation.

channel.addConfirmListener(new ConfirmListener() {

    @Override
    public void handleNack(long deliveryTag, boolean multiple) throws IOException {
        System.out.println("nack: deliveryTag = "+deliveryTag+" multiple: "+multiple);
    }

    @Override
    public void handleAck(long deliveryTag, boolean multiple) throws IOException {
        System.out.println("ack: deliveryTag = "+deliveryTag+" multiple: "+multiple);
    }
});

(2) loss of data message queue

Where the message queue is typically lost opening persistence disk configuration, and this configuration may confirm persistence mechanisms used in conjunction with, can persist after the hard disk, to send ack a producer, the producer if not received ack message, retransmits information.

How persistent hard disk:

① the queue of persistent identity durable set to true,

② When the message is sent deliveryMode = 2

Even arranged such rabbitMQ hung up, restart can recover data

(3) the loss of consumer data

Consumers are generally thought lost data using an automatic confirmation message mode. After the consumer receives the message, rabbitMQ will immediately delete the message from the queue inside, which is the case if the consumer is not an exception but the message is lost in time data.

Solution: manual confirmation message.

 Seven, how to ensure the timing of the message?

FIFO queue, such linkedBlockingQueue.

Guess you like

Origin www.cnblogs.com/wudi521/p/11697703.html