[英]Failed to invoke successfully Error There was a problem with the eventhub Error: 14 UNAVAILABLE: Connect Failed --while invoking in hyperledger fabric
I'm getting this error when trying to invoke in Hyperledger-Fabric.尝试在 Hyperledger-Fabric 中调用时出现此错误。 Please find my code below.请在下面找到我的代码。
var FabricClient = require('fabric-client');
var fabricClient = new FabricClient();
fabricClient.loadFromConfig(configFilePath);
var connection = fabricClient;
var tx_id = null;
var peers = connection.getPeersForOrg();
var event_hub = connection.getEventHub(peers[0].getName());
var channel = connection.getChannel();
connection.initCredentialStores().then(() => {
return connection.getUserContext('admin', true);
}).then((user_from_store) => {
if (user_from_store && user_from_store.isEnrolled()) {
console.log('Successfully loaded user1 from persistence');
// member_user = user_from_store;
} else {
throw new Error('Failed to get user1.... run registerUser.js');
}
tx_id = connection.newTransactionID();
console.log("Assigning transaction_id: ", tx_id._transaction_id);
var request = {
chaincodeId: 'mycc',
fcn: 'createFruit',
args: ['Fruit1', 'Banana2', '10', 'DineshDSV'],
chainId: 'mychannel',
txId: tx_id
};
// send the transaction proposal to the peers
return channel.sendTransactionProposal(request);
}).then((results) => {
var proposalResponses = results[0];
var proposal = results[1];
let isProposalGood = false;
if (proposalResponses && proposalResponses[0].response &&
proposalResponses[0].response.status === 200) {
isProposalGood = true;
console.log('Transaction proposal was good');
} else {
console.error('Transaction proposal was bad');
}
if (isProposalGood) {
console.log(util.format(
'Successfully sent Proposal and received ProposalResponse: Status - %s, message - "%s"',
proposalResponses[0].response.status, proposalResponses[0].response.message));
console.log(proposalResponses[0].response)
// build up the request for the orderer to have the transaction committed
var request = {
proposalResponses: proposalResponses,
proposal: proposal
}
var transaction_id_string = tx_id.getTransactionID();
//Get the transaction ID string to be used by the event processing
var promises = [];
var sendPromise = channel.sendTransaction(request);
promises.push(sendPromise);
let txPromise = new Promise((resolve, reject) => {
let handle = setTimeout(() => {
event_hub.disconnect();
resolve({event_status : 'TIMEOUT'});
//we could use
reject(new Error('Trnasaction did not complete within 30 seconds'));
}, 3000);
event_hub.connect();
event_hub.registerTxEvent(transaction_id_string, (tx, code) => {
// this is the callback for transaction event status
// first some clean up of event listener
clearTimeout(handle);
event_hub.unregisterTxEvent(transaction_id_string);
event_hub.disconnect();
// now let the application know what happened
var return_status = {event_status : code, tx_id : transaction_id_string};
if (code !== 'VALID') {
console.error('The transaction was invalid, code = ' + code);
resolve(return_status); // we could use reject(new Error('Problem with the tranaction, event status ::'+code));
} else {
console.log('The transaction has been committed on peer ' + event_hub._ep._endpoint.addr);
resolve(return_status);
}
}, (err) => {
//this is the callback if something goes wrong with the event registration or processing
reject(new Error('There was a problem with the eventhub ::'+err));
});
});
promises.push(txPromise);
return Promise.all(promises);
} else {
console.error('Failed to send Proposal or receive valid response. Response null or status is not 200. exiting...');
throw new Error('Failed to send Proposal or receive valid response. Response null or status is not 200. exiting...');
}
}).then((results) => {
console.log('Send transaction promise and event listener promise have completed');
// check the results in the order the promises were added to the promise all list
if (results && results[0] && results[0].status === 'SUCCESS') {
console.log('Successfully sent transaction to the orderer.');
} else {
console.error('Failed to order the transaction. Error code: ' + response.status);
}
if(results && results[1] && results[1].event_status === 'VALID') {
console.log('Successfully committed the change to the ledger by the peer');
} else {
console.log('Transaction failed to be committed to the ledger due to ::'+results[1].event_status);
}
}).catch((err) => {
console.error('Failed to invoke successfully :: ' + err);
});
I have tried using the CLI its working absolutely file.我已经尝试使用 CLI 其工作绝对文件。 All the peers are running fine.所有的同行都运行良好。 and the response Im getting in my console is:我在控制台中得到的响应是:
Successfully loaded user1 from persistence
Assigning transaction_id: f64c079e92fd111bf71172f326e4d9db188ea3a38317152cdfbf24c6f65fbded
Transaction proposal was good
Successfully sent Proposal and received ProposalResponse: Status - 200, message - ""
{ status: 200, message: '', payload: <Buffer > }
Failed to invoke successfully:: Error: There was a problem with the eventhub ::Error: 14 UNAVAILABLE: Connect Failed
Please help me on how to rectify this error.请帮助我解决此错误。 Thanks in advance for suggestions.提前感谢您的建议。
I have solved this by changing the below line我通过更改以下行解决了这个问题
console.log('The transaction has been committed on peer ' + event_hub._ep._endpoint.addr);
to至
console.log('The transaction has been committed on peer ' + event_hub._endpoint.addr);
Its the change in version of fabric-client.它是fabric-client版本的变化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.