|
@@ -2,8 +2,11 @@ package es.uv.garcosda.controllers;
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
+import org.springframework.amqp.core.Message;
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.messaging.handler.annotation.Header;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
@@ -32,10 +35,6 @@ public class WorkerController {
|
|
|
|
|
|
@RabbitListener(queues = {"${rabbitmq.queue.name.user}"})
|
|
|
public void compute(User user) {
|
|
|
-
|
|
|
- HttpEntity<MailDTO> request = new HttpEntity<>(new MailDTO("system@mailer.com", "system@mailer.com", "New account created", "Created new account for user "+user.getEmail()));
|
|
|
- restTemplate.postForObject("http://localhost:8080/api/v1/mailbox", request, String.class);
|
|
|
-
|
|
|
try {
|
|
|
Thread.sleep(10 * 1000);
|
|
|
}
|
|
@@ -44,17 +43,13 @@ public class WorkerController {
|
|
|
}
|
|
|
|
|
|
String passwd = generatePasswd(6);
|
|
|
- request = new HttpEntity<>(new MailDTO("system@mailer.com", user.getEmail(), "Welcome to Mailer APP", "Welcome to mailer app. You can access to your account by using this password: "+passwd));
|
|
|
+ HttpEntity<MailDTO> request = new HttpEntity<>(new MailDTO("system@mailer.com", user.getEmail(), "Welcome to Mailer APP", "Welcome to mailer app. You can access to your account by using this password: "+passwd));
|
|
|
restTemplate.postForObject("http://localhost:8080/api/v1/mailbox", request, String.class);
|
|
|
|
|
|
}
|
|
|
|
|
|
@RabbitListener(queues = {"${rabbitmq.queue.name.recover}"})
|
|
|
- public void computePasswd(User user) {
|
|
|
-
|
|
|
- HttpEntity<MailDTO> request = new HttpEntity<>(new MailDTO("system@mailer.com", "system@mailer.com", "Password recover", "Password recover issued by "+user.getEmail()));
|
|
|
- restTemplate.postForObject("http://localhost:8080/api/v1/mailbox", request, String.class);
|
|
|
-
|
|
|
+ public void computePasswd(User user) {
|
|
|
try {
|
|
|
Thread.sleep(10 * 1000);
|
|
|
}
|
|
@@ -63,8 +58,21 @@ public class WorkerController {
|
|
|
}
|
|
|
|
|
|
String passwd = generatePasswd(6);
|
|
|
- request = new HttpEntity<>(new MailDTO("system@mailer.com", user.getEmail(), "Your new password", "Your new password is: "+passwd));
|
|
|
+ HttpEntity<MailDTO> request = new HttpEntity<>(new MailDTO("system@mailer.com", user.getEmail(), "Your new password", "Your new password is: "+passwd));
|
|
|
restTemplate.postForObject("http://localhost:8080/api/v1/mailbox", request, String.class);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @RabbitListener(queues = {"${rabbitmq.queue.name.system}"})
|
|
|
+ public void computeSystem(User user, Message message) {
|
|
|
+ HttpEntity<MailDTO> request;
|
|
|
+ if(message.getMessageProperties().getReceivedRoutingKey().toLowerCase().equals("k.new_user")) {
|
|
|
+ request = new HttpEntity<>(new MailDTO("system@mailer.com", "system@mailer.com", "New account created", "Created new account for user "+user.getEmail()));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ request = new HttpEntity<>(new MailDTO("system@mailer.com", "system@mailer.com", "Password recover", "Password recover issued by "+user.getEmail()));
|
|
|
+ }
|
|
|
+
|
|
|
+ restTemplate.postForObject("http://localhost:8080/api/v1/mailbox", request, String.class);
|
|
|
+ }
|
|
|
}
|