Kenmegne
7 days ago 23a46b4be35277e06ec89f48730eeb694e686be8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.megatim.fdxconsultation.service.impl.camel;
 
import com.megatim.fdxcommons.model.camel.BrokerProperties;
import com.megatim.fdxcommons.model.camel.FileProperties;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import org.apache.camel.cdi.CdiCamelConfiguration;
import org.apache.camel.cdi.CdiCamelContext;
import org.apache.camel.component.rabbitmq.RabbitMQComponent;
 
@Singleton
@Startup
public class CamelBootstrap {
 
    @Inject
    private CdiCamelContext camelContext;
 
    @PostConstruct
    public void init() {
        try {
            FileProperties fileProperties = new FileProperties(com.megatim.fdxcommons.tools.context.AppContext.BROKER_FILE_PATH);
 
            // Add RabbitMQ Component with connection details
            RabbitMQComponent rabbitMQComponent = new RabbitMQComponent();
            rabbitMQComponent.setHostname(brokerHostName(fileProperties));
            rabbitMQComponent.setPortNumber(brokerPortNumber(fileProperties));
            rabbitMQComponent.setUsername(brokerUserName(fileProperties));
            rabbitMQComponent.setPassword(brokerPassword(fileProperties));
 
            camelContext.addComponent("rabbitmq", rabbitMQComponent);
 
            camelContext.start();
        } catch (IOException ex) {
            Logger.getLogger(CamelBootstrap.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
        }
    }
 
    public static void configuration(@Observes CdiCamelConfiguration configuration) {
 
        System.out.println("<-------------------------------------------------------------------------------------------->");
        System.out.println("<-------------------------------------------------------------------------------------------->");
        System.out.println("<-------------------------------------------------------------------------------------------->");
        System.out.println("<-------------------------------------------------------------------------------------------->");
        System.out.println("<-------------------------------------------------------------------------------------------->");
 
        System.out.println("INSIDE CONFIGURE OF ROUTE");
 
        System.out.println("<-------------------------------------------------------------------------------------------->");
        System.out.println("<-------------------------------------------------------------------------------------------->");
        System.out.println("<-------------------------------------------------------------------------------------------->");
        System.out.println("<-------------------------------------------------------------------------------------------->");
 
//        configuration.autoConfigureRoutes(false);
        configuration.autoStartContexts(false);
    }
 
    private String brokerHostName(FileProperties fileProperties) throws IOException {
        return fileProperties.properties().getProperty(BrokerProperties.HOSTNAME);
    }
 
    private int brokerPortNumber(FileProperties fileProperties) throws IOException {
        return Integer.parseInt(fileProperties.properties().getProperty(BrokerProperties.PORT_NUMBER));
    }
 
    private String brokerUserName(FileProperties fileProperties) throws IOException {
        return fileProperties.properties().getProperty(BrokerProperties.USER_NAME);
    }
 
    private String brokerPassword(FileProperties fileProperties) throws IOException {
        return fileProperties.properties().getProperty(BrokerProperties.PASSWORD);
    }
}