Hi anh Dũng, Em có 2 module Java cùng lấy thông tin dữ liệu trên cache, em đang sử dụng redis thì có cách nào đồng bộ giữa 2 module như kiểu:
khi có module A đọc hoặc ghi thì module B sẽ đợi module A xong r mới thực hiện và ngược lại
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Đây là bài toán tương đối nan giải, anh thường sẽ không làm như vậy mà sẽ sử dụng 1 consumer duy nhất để thực hiện việc update thôi, tuy nhiên nếu em vẫn muốn làm kiểu này em có thể dùng cách sau, code này sẽ được triển khai ở mỗi server:
1. Sử dụng 1 map để lưu trạng thái lock, ví dụ update_lock
2. Sử dụng 1 channel để thông báo việc update đã xong
Code logic thế này:
Em hiểu ý anh chứ?
vâng, em hiểu cách trên r anh. Cách tốt nhất là nên dùng 1 consumer cho việc dùng chung dữ liệu với nhiều module à anh?
Ừ, theo cách đó thì việc xử lý concurrent cũng dễ hơn, xử lý transaction cũng dễ hơn. Cách kia thì cũng có rủi ro là phức tạp, với cả nhiều khi thông báo không đến được thì lại timeout (mặc dù trường hợp timeout cũng ít thôi)