-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHOW_TO_INTEGRATE.txt
174 lines (127 loc) · 6.6 KB
/
HOW_TO_INTEGRATE.txt
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
Config is a module that stores configuration settings related to other modules.
Most of the modules, expecially business ones need Config to store their Settings which can be retrieved later
and or to get global settings (Application -FluxFmc- wise settings), example flux_local_nation_code.
Integration with this module is easy if the following steps are followed correctly :
1.
There are 2 ears related to config module :
1. Config Module(the app)
2. Uvms-Config, or eitherwise called Config Library.
Ps: I know naming convention was really bad, but, hey this is how it is!
We need to include the dependency of Config Library in the app that needs to use Config module :
<dependency>
<groupId>eu.europa.ec.fisheries.uvms</groupId>
<artifactId>uvms-config</artifactId>
<version>${uvms.config.version}</version>
</dependency>
Fetch the latest released version of it.
2.
Once we have included this dependency even if we compiled our app it wouldn't deploy because we need to
implement some interfaces which are defined in uvms-config but not implemented!
There are 3 such interfaces :
2.1
@Local
public interface ConfigHelper {
1. List<String> getAllParameterKeys();
2. String getModuleName();
3. EntityManager getEntityManager();
}
2.1.1 The getAllParameterKeys() will have all the settings keys for the module.
2.1.2 The getModuleName() will need to return the name of the module (example in case of mdr it will return "mdr")
2.1.3 The getEntityManager() needs to return a properly initialized EntityManager, and for this you
need to configure/declare a datasource (persistence.xml of the module) that can have access to Config tables.
It is used internally to get/store Parameters from the Parameter table.
Here you have an example configuration of such datasource (for MDR module) :
<persistence-unit name="mdrConfig" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>jdbc/uvms_config</jta-data-source>
<class>eu.europa.ec.fisheries.uvms.config.service.entity.Parameter</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
</properties>
</persistence-unit>
Here you have an example of implementation of the ConfigHelper interface (from rules module)
@Stateless
public class MdrConfigRegistration implements ConfigHelper {
@PersistenceContext(unitName = "mdrConfig")
private EntityManager em;
@Override
public List<String> getAllParameterKeys() {
return new ArrayList<String>(){{add("mdr.parameter.key");}};
}
@Override
public String getModuleName() {
return "mdr";
}
@Override
public EntityManager getEntityManager() {
return em;
}
}
2.2 Implement the ConfigMessageProducer interface :
@Local
public interface ConfigMessageProducer {
String sendConfigMessage(String text) throws ConfigMessageException;
}
This bean will be used to send messages to Config module.
It is of vital importance that each sent message has set the JmsReplyTo property, otherwise
Config won't know who to send the response to!
Example Implementation (from mdr module) :
@Stateless
@Slf4j
public class MdrConfigConsumerBeanImpl extends AbstractConsumer implements ConfigMessageConsumer {
private final static Logger LOG = LoggerFactory.getLogger(MdrConfigConsumerBeanImpl.class);
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public <T> T getConfigMessage(String correlationId, Class type) throws ConfigMessageException {
try {
return getMessage(correlationId, type);
} catch (MessageException e) {
LOG.error("[ERROR] Error when getting config message {}", e.getMessage());
throw new ConfigMessageException("[ Error when getting config message. ]");
}
}
@Override
public String getDestinationName() {
return MessageConstants.QUEUE_MDR;
}
}
2.3 Implement the ConfigMessageConsumer interface :
@Local
public interface ConfigMessageConsumer {
public <T> T getConfigMessage(String correlationId, Class type) throws ConfigMessageException;
}
When you have send the message to config through the ConfigMessageProducer bean you have set also
the JmsReplyTo property. This means that the response will be sent to that (JmsReplyTo) queue.
This consumer needs to consume ()that response from the same queue that we had set the JmsReplyTo
to point to.
Example Implementation (from mdr module) :
@Stateless
@Slf4j
public class MdrConfigProducerBeanImpl extends AbstractProducer implements ConfigMessageProducer {
/**
* Once a message is sent to config, config needs to know where to send the response... This is MDRQueue in case of MDR modules..
*/
private Queue mdrINQueue;
@PostConstruct
public void initMdrQueue(){
mdrINQueue = JMSUtils.lookupQueue(MessageConstants.QUEUE_MDR);
}
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public String sendConfigMessage(String textMsg) {
try {
return sendModuleMessage(textMsg, mdrINQueue);
} catch (MessageException e) {
log.error("[ERROR] Error while trying to send message to Config! Check MdrConfigProducerBeanImpl..");
}
return StringUtils.EMPTY;
}
@Override
public String getDestinationName() {
return MessageConstants.QUEUE_CONFIG;
}
}
Once you have correctly included the uvms-config dependency/configured the datasource/implemented the 3 interfaces
you can compile and deploy your app and automatically it will be present in Config Module and your app can (for Example)
request settings from Config module now.
For the purpose of requesting settings from Config module you can use the (very easy hookable) AbstractConfigCache class!