public class KafkaController {
@Autowired
private KafkaTemplate<String,BankAccount> kafkaTemplate;
private static final String TOPIC = "my-topic";
@GetMapping("/publish/{message}")
public String postKafka(@PathVariable("message") final String message){
BankAccount bankAccount= new BankAccount();
bankAccount.setBalance(120.0);
kafkaTemplate.send(TOPIC,bankAccount);
return "Succesfully";
}
}
我希望return new DefaultKafkaConsumerFactory<>(
consumerConfigs(),
new StringDeserializer(),
new JsonDeserializer<>(BankAccount.class));
的输出为2,但实际上我得到了1。如何为现有变量分配新值?
答案 0 :(得分:1)
您需要使用multiprocessing shared values;
import multiprocessing
import ctypes
def foo(var, new_value):
var.value = new_value
x = multiprocessing.Value(ctypes.c_int, 1)
print(x.value)
p = multiprocessing.Process(target=foo, args=(x,2))
p.start()
p.join()
print(x.value)