SpringCloud 方法觸發(fā)的輸出

2023-12-13 11:48 更新

可以通過(guò)調(diào)用方法(例如啟動(dòng)a并發(fā)送消息時(shí)調(diào)用Scheduler)來(lái)觸發(fā)輸出消息,如以下示例所示:

Groovy DSL。 

def dsl = Contract.make {
	// Human readable description
	description 'Some description'
	// Label by means of which the output message can be triggered
	label 'some_label'
	// input to the contract
	input {
		// the contract will be triggered by a method
		triggeredBy('bookReturnedTriggered()')
	}
	// output message of the contract
	outputMessage {
		// destination to which the output message will be sent
		sentTo('output')
		// the body of the output message
		body('''{ "bookName" : "foo" }''')
		// the headers of the output message
		headers {
			header('BOOK-NAME', 'foo')
		}
	}
}

YAML。 

# Human readable description
description: Some description
# Label by means of which the output message can be triggered
label: some_label
input:
  # the contract will be triggered by a method
  triggeredBy: bookReturnedTriggered()
# output message of the contract
outputMessage:
  # destination to which the output message will be sent
  sentTo: output
  # the body of the output message
  body:
    bookName: foo
  # the headers of the output message
  headers:
    BOOK-NAME: foo

在前面的示例情況下,如果執(zhí)行了稱為bookReturnedTriggered的方法,則輸出消息將發(fā)送到output在消息發(fā)布者方面,我們生成了一個(gè)測(cè)試,該測(cè)試調(diào)用該方法來(lái)觸發(fā)消息。使用者方面,您可以使用some_label來(lái)觸發(fā)消息。

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)