|
20 | 20 | import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo;
|
21 | 21 | import org.apache.eventmesh.common.config.CommonConfiguration;
|
22 | 22 | import org.apache.eventmesh.common.protocol.SubscriptionItem;
|
| 23 | +import org.apache.eventmesh.common.protocol.http.HttpEventWrapper; |
| 24 | +import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; |
23 | 25 | import org.apache.eventmesh.common.utils.ConfigurationContextUtil;
|
| 26 | +import org.apache.eventmesh.common.utils.IPUtils; |
24 | 27 | import org.apache.eventmesh.common.utils.JsonUtils;
|
25 | 28 | import org.apache.eventmesh.registry.nacos.constant.NacosConstant;
|
26 | 29 | import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer;
|
| 30 | +import org.apache.eventmesh.runtime.configuration.EventMeshHTTPConfiguration; |
27 | 31 | import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupConf;
|
28 | 32 | import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupMetadata;
|
29 | 33 | import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupTopicConf;
|
|
38 | 42 | import java.util.Map;
|
39 | 43 | import java.util.Optional;
|
40 | 44 |
|
41 |
| -import org.slf4j.Logger; |
42 |
| -import org.slf4j.LoggerFactory; |
43 |
| - |
44 | 45 | import com.google.common.collect.Maps;
|
45 | 46 |
|
| 47 | +import lombok.extern.slf4j.Slf4j; |
| 48 | + |
46 | 49 | /**
|
47 | 50 | * EventProcessor
|
48 | 51 | */
|
| 52 | +@Slf4j |
49 | 53 | public abstract class AbstractEventProcessor implements AsyncHttpProcessor {
|
50 | 54 |
|
51 |
| - private static final Logger LOGGER = LoggerFactory.getLogger("AbstractEventProcessor"); |
52 |
| - |
53 | 55 | protected transient EventMeshHTTPServer eventMeshHTTPServer;
|
54 | 56 |
|
55 | 57 | public AbstractEventProcessor(EventMeshHTTPServer eventMeshHTTPServer) {
|
@@ -97,7 +99,7 @@ protected void updateMetadata() {
|
97 | 99 | eventMeshHTTPServer.getRegistry().registerMetadata(metadata);
|
98 | 100 |
|
99 | 101 | } catch (Exception e) {
|
100 |
| - LOGGER.error("[LocalSubscribeEventProcessor] update eventmesh metadata error", e); |
| 102 | + log.error("[LocalSubscribeEventProcessor] update eventmesh metadata error", e); |
101 | 103 | }
|
102 | 104 | }
|
103 | 105 |
|
@@ -148,4 +150,36 @@ protected String getTargetMesh(String consumerGroup, List<SubscriptionItem> subs
|
148 | 150 | }
|
149 | 151 | return targetMesh;
|
150 | 152 | }
|
| 153 | + |
| 154 | + /** |
| 155 | + * builder response header map |
| 156 | + * @param requestWrapper requestWrapper |
| 157 | + * @return Map |
| 158 | + */ |
| 159 | + protected Map<String, Object> builderResponseHeaderMap(HttpEventWrapper requestWrapper) { |
| 160 | + Map<String, Object> responseHeaderMap = new HashMap<>(); |
| 161 | + EventMeshHTTPConfiguration eventMeshHttpConfiguration = eventMeshHTTPServer.getEventMeshHttpConfiguration(); |
| 162 | + responseHeaderMap.put(ProtocolKey.REQUEST_URI, requestWrapper.getRequestURI()); |
| 163 | + responseHeaderMap.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHCLUSTER, |
| 164 | + eventMeshHttpConfiguration.getEventMeshCluster()); |
| 165 | + responseHeaderMap.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, |
| 166 | + IPUtils.getLocalAddress()); |
| 167 | + responseHeaderMap.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, |
| 168 | + eventMeshHttpConfiguration.getEventMeshEnv()); |
| 169 | + responseHeaderMap.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, |
| 170 | + eventMeshHttpConfiguration.getEventMeshIDC()); |
| 171 | + return responseHeaderMap; |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * validation sysHeaderMap is null |
| 176 | + * @param sysHeaderMap sysHeaderMap |
| 177 | + * @return Returns true if any is empty |
| 178 | + */ |
| 179 | + protected boolean validateSysHeader(Map<String, Object> sysHeaderMap) { |
| 180 | + return StringUtils.isAnyBlank(sysHeaderMap.get(ProtocolKey.ClientInstanceKey.IDC).toString(), |
| 181 | + sysHeaderMap.get(ProtocolKey.ClientInstanceKey.PID).toString(), |
| 182 | + sysHeaderMap.get(ProtocolKey.ClientInstanceKey.SYS).toString()) |
| 183 | + || !StringUtils.isNumeric(sysHeaderMap.get(ProtocolKey.ClientInstanceKey.PID).toString()); |
| 184 | + } |
151 | 185 | }
|
0 commit comments