我有一个Java后端,可以在其中通过以下方式向主题发送消息
jmsTemplate.convertAndSend("topic", "Hello World!");
Run Code Online (Sandbox Code Playgroud)
在我的JavaScript前端中,我使用mqttJS连接到activeMQ并接收消息:
let mqtt = require('mqtt')
let options ={
clientId:"test",
username:"username",
useSSL: true,
password:"password",
clean:true};
let client = mqtt.connect(
'wss://someUrl.com:61619',
options);
client.on('connect', function () {
client.subscribe('myTopic', function (err) {
if (!err) {
console.log("successfully connected to myTopic'");
}
})
});
client.on('message', function (topic, message) {
console.log(message.toString());
});
Run Code Online (Sandbox Code Playgroud)
我从后端收到的消息是这样的:
S?A S?)?x-opt-jms-destQ?x-opt-jms-msg-typeQ Ss? f
?/ID:myID@?topic://myTopic@@@@? j??< St?
e Sw? Hello World!
Run Code Online (Sandbox Code Playgroud)
我的讯息是“ Hello World!” 在那儿。但是也有很多不可读的地方,我想从标题开始。
我在后端尝试了不同的MessageConverters,在前端尝试了不同的解析器。没用。
我需要做什么才能获得“ Hello World!” 作为消息?还是有使用jms发送消息的更好方法,这是必需的。
我正在处理一个项目,我想标记或提供版本号。当合并发生并且我的 CI/CD 成功运行时,我希望 gitlab 在我的 gitci.yml 文件中标记 V 1.0、1.1 等。
我的服务休息服务中有一个函数 createObject():
@Service
public class MyService {
//Repos and contructor
@Transactional
public ObjectDto createObject(Object) {
Mother mother = new Mother(name, age);
Kid kid = new Kid(name, age);
mother.addKid(kid);
this.motherRepo.saveAndFlush(mother);
Long kidId = kid.getId();
doStuffWithKidId();
return new ObjectDto()
.withMother(mother)
.withKid(kid)
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
我的母亲/孩子实体基本上是这样的:
@Entity
@Table("mother")
public class mother() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id)
private Long id;
//other attributes, including @OneToMany for Kid
//Getter/Setter
}
Run Code Online (Sandbox Code Playgroud)
Kid 有一个类似的实体。
如您所见,id 是由数据库设置的。实体中没有 id 的设置器。构造函数也没有 id。
现在我想测试我的服务。我模拟了我的存储库并想验证我的 ObjectDto 是否包含值,例如 id。
@RunWith(MockitoJUnitRunner.class)
@SpringBootTest
public MyServiceTest …
Run Code Online (Sandbox Code Playgroud) java ×2
decode ×1
git ×1
git-tag ×1
gitlab ×1
gitversion ×1
javascript ×1
jms ×1
junit ×1
mockito ×1
mqtt ×1
spring-boot ×1
testing ×1
versioning ×1