I know that might sound like a stupid question but I have a Spring app which is designed to communicate with a queue instance via cloudamqp (rabbitmq). Basically it is a sensor simulator and I want to get the data from a csv and publish it into my queue. (this app is the producer).
I would like to execute a method from a class and I don't know how to do this. (I guess one way would be to callthat method in my main function), but is this good practice? Usually in Spring Boot apps you don't write anything in your main function and you just let it be like that:
public static void main(String[] args) {
SpringApplication.run(Producer1Application.class, args);
}```
The code I would like to execute when i run the Spring app is this:
```java
@Service
@Configuration
public class RabbitMQSender {
@Autowired
private AmqpTemplate rabbitTemplate;
@Autowired
private Queue queue;
@Autowired
Parser parser;
public void send(MeasurementMQ measurementMQ) throws InterruptedException {
List<MeasurementMQ> measurementMQS = parser.readFromCSV();
for(MeasurementMQ measurement: measurementMQS){
rabbitTemplate.convertAndSend(queue.getName(), measurement);
System.out.println("Sending message to queue: " + measurementMQ.toString());
Thread.sleep(1000);
}
}```
(more specifically the `send` method).
I don't have experience with these types of apps (not-web), because everything that I did using Spring was for Web, and, so I had some Tomcat server running on 8080 which solved this problem. Would appreciate some help. Thanks!