-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from JoshYuJump/main
Tested bali 3.2.1
- Loading branch information
Showing
12 changed files
with
87 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
from bali.decorators import event_handler | ||
|
||
|
||
@event_handler('hello') | ||
def hello_handle(event): | ||
pass | ||
class EventHandler: | ||
@event_handler('HelloSaid') | ||
def handle_hello_said(self, event): | ||
self.prepare(event) | ||
print('handle event: ', event) | ||
|
||
@event_handler('HiSaid') | ||
def handle_hi_said(self, event): | ||
self.prepare(event) | ||
print('handle event: ', event) | ||
|
||
def prepare(self, event): | ||
print('prepare event: ', event) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
|
||
from bali.core import _settings | ||
from bali.events import Event, dispatch | ||
|
||
amqp_uri = os.getenv('AMQP_SERVER_ADDRESS', default='amqp://127.0.0.1:5672') | ||
|
||
|
||
_settings.AMQP_CONFIGS = { | ||
'default': { | ||
'AMQP_SERVER_ADDRESS': amqp_uri, | ||
'EXCHANGE_NAME': 'ms.events', | ||
'EXCHANGE_TYPE': 'fanout', | ||
} | ||
} | ||
|
||
|
||
class HelloSaidEvent(Event): | ||
"""Hello said event""" | ||
type: str = 'HelloSaid' | ||
name: str = '' | ||
|
||
|
||
class HiSaidEvent(Event): | ||
"""Hi said event""" | ||
type: str = 'HiSaid' | ||
name: str = '' | ||
|
||
|
||
def run(): | ||
event = HelloSaidEvent(name='Jack') | ||
dispatch(event) | ||
print('Dispatched event: ', event) | ||
|
||
event = HiSaidEvent(name='Jerry') | ||
dispatch(event) | ||
print('Dispatched event: ', event) | ||
|
||
|
||
if __name__ == '__main__': | ||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters