January 2012
Intermediate to advanced
336 pages
8h 12m
English
When we modified the Account earlier, we made it write out each transaction message as amount,account_number. The TransactionProcessor needs the account_number to find an account in the database and update its balance:
| databases/01/lib/transaction_processor.rb | |
| | require_relative 'transaction_queue' |
| | require_relative 'account' |
| | |
| | transaction_queue = TransactionQueue.new |
| | puts "transaction processor ready" |
| | loop do |
| | transaction_queue.read do |message| |
| | sleep 1 |
* | transaction_amount, number = message.split(/,/) |
* | account = Account.find_by_number!(number.strip) |
* | new_balance = account.balance + transaction_amount.to_i |
* | account.balance = new_balance |
* | account.save |
| | end |
| | end |
However, looking at the message ...
Read now
Unlock full access