首次提交代码
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.gzzn.omms.msgexchangeapi.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
|
||||
@Service
|
||||
public class ExchangeServiceImpl implements IExchangeService {
|
||||
|
||||
@Override
|
||||
public String xmlToJson(String xml) throws JsonParseException, JsonMappingException, IOException {
|
||||
|
||||
ObjectMapper xmlMapper = new XmlMapper();
|
||||
Map map = xmlMapper.readValue(xml, Map.class);
|
||||
|
||||
ObjectMapper jsonMapper = new ObjectMapper();
|
||||
String json = jsonMapper.writeValueAsString(map);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.gzzn.omms.msgexchangeapi.service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
|
||||
/**
|
||||
* 消息转换服务
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
public interface IExchangeService {
|
||||
|
||||
public String xmlToJson(String xml)throws JsonParseException, JsonMappingException, IOException;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.gzzn.omms.msgexchangeapi.service;
|
||||
|
||||
public interface IKafkaService {
|
||||
public void msgSend(String topic,String msg) ;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.gzzn.omms.msgexchangeapi.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class KafkaServiceImpl implements IKafkaService{
|
||||
|
||||
@Autowired
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
public void msgSend(String topic, String msg) {
|
||||
kafkaTemplate.send(topic, msg);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user