How to set the max receive message length in Google Cloud request? - google-cloud-platform

I have the following Google Cloud call:
var builder = new TextToSpeechClientBuilder();
builder.JsonCredentials = #"...";
var client = builder.Build();
var data = client.SynthesizeSpeech(new SynthesisInput { Ssml = text },
new VoiceSelectionParams { LanguageCode = culture.TwoLetterISOLanguageName },
new AudioConfig { AudioEncoding = AudioEncoding.Linear16, SampleRateHertz = 8000 }).AudioContent;
It throws the following exception:
Grpc.Core.RpcException: 'Status(StatusCode="ResourceExhausted", Detail="Received message larger than max (4675411 vs. 4194304)")'
The request is less than 2000 bytes, so it seems that the response is too big. The server wants to send the response, but the client can't accept it.
How to increase this limit?
UPDATE: Since version 2.2.0 it is possible to set the max response size:
var channelOptions = GrpcChannelOptions.Empty
.WithKeepAliveTime(TimeSpan.FromMinutes(1))
.WithEnableServiceConfigResolution(false)
.WithMaxReceiveMessageSize(1024 * 1024 * 1024);
var builder = new TextToSpeechClientBuilder();
builder.JsonCredentials = jsonCredentials;
builder.GrpcChannelOptions = channelOptions;

In order to overcome the error Received message larger than max (4675411 vs. 4194304), you need to set the inbound message size to a greater value. You can do it when instantiating your builder, similarly as when creating a channel. Below, it is how you can do it:
textToSpeechClient = TextToSpeechClient.create(TextToSpeechSettings
.newBuilder()
.setTransportChannelProvider(
TextToSpeechSettings.defaultGrpcTransportProviderBuilder()
.setMaxInboundMessageSize(8790801)
.build())
.build());
Here is the documentation for the setMaxInboundMessageSize method.
UPDATE: As I understand you want to use C# and since I could not find a method to set the inbound's message size, such as in Java (above). I have opened a a Public issue within Google. Although, I do not have an ETA for it, you can keep track here.

Related

EventHub EventDataBatch exceed MaxMessageSize

I am using Microsoft.Azure.EventHubs 2.0.0 NuGet to add messages to batch:
private EventDataBatch _currentBatch;
_currentBatch = _eventHubClient.CreateBatch();
...
var json = #event.ToEventJson();
var data = new EventData(Encoding.UTF8.GetBytes(json));
if (_currentBatch.TryAdd(data))
{
return;
}
But the created batch randomly (not on all created batches) throws:
{Microsoft.Azure.EventHubs.MessageSizeExceededException: The received
message (delivery-id:0, size:262192 bytes) exceeds the limit (262144
bytes) currently allowed on the link.
during
await _eventHubClient.SendBatchAsync(batch);
It is deterministic as I have set of data that throws this error always during the tests.

Cannot Get a Azure Webjobs Job To Send An Email Stored in Blob Storage As an Htm File

Having problems diagnosing why a webjob won't work. I'm trialing Azure.
There's no errors. But I am never receiving the email which the WebJob is meant to be sending.
I tried clicking the big Functions rectangle in the top right of the header (it had an exclamation point icon in it). But that was just an empty page with the footer flush up against the header.
The code is simply:
public static void ProcessQueueMessage(
[BlobInput("notifications/{name}")] Stream input,
[BlobOutput("notifications/{name}")] Stream output)
{
using (StreamReader sr = new StreamReader(input))
{
using (var smtp = new SmtpClient())
{
smtp.Host = "smtp.adam.com.au";
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("username", "password");
smtp.Timeout = 5000;
var mailMessage = new MailMessage();
mailMessage.To.Add(new MailAddress("anemail#gmail.com"));
mailMessage.From = new MailAddress("dave#dave.com");
mailMessage.Subject = "nice email";
mailMessage.Body = sr.ReadToEnd();
mailMessage.IsBodyHtml = true;
smtp.Send(mailMessage);
}
}
}
This is black box to me. How can I diagnose the problem?
First of all, you are using the old version of the SDK. The new one, Beta, has different attribute names. Without upgrading, you will not be able to see any data in the dashboard.
Second, you see the exclamation point because the connection string is not properly configured in the Configure tab of the website. Set a connection string named AzureJobsDashboard.
Last, here is how you can debug the webjob in the cloud http://blog.mitchdenny.com/2014/02/11/remotely-debugging-web-jobs-on-windows-azure-websites/

Copy Web Service in SharePoint for Office 365

I am trying to upload files greater than 100 MB size to SharePoint Portal for Office 365. I have tried three different ways to achieve the same.
Copy Web Service, along with the httpRuntime Setting in place with maxRequestLength set as 2097151 and executionTimeout as 14400. Also, I did try setting the Timeout as "Infinite" and "60000".
Error: The underlying connection was closed: An unexpected error occurred on a send.
Web Client, using UploadDataAsync method to "PUT" the file bytes to the destination Url. Even with this, the httpRuntime setting was in place as above.
Error: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
HttpWebRequest, with ServicePointManager.Expect100Continue set to false. Also tried the same with SendChunked as both true and false.
Error: The request was aborted: The request was canceled.
Apart from all these, I have also added
protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
System.Net.HttpWebRequest webRequest =
(System.Net.HttpWebRequest) base.GetWebRequest(uri);
webRequest.KeepAlive = false;
return webRequest;
}
in the proxy class generated for Copy service. The limitation is I can't use CSOM to upload the files.
And still the Upload request times out every time. Any help would be very much appreciated.
Thanks in advance.
Try using the following piece of code :-
WebRequest webRequest = WebRequest.Create(url);
HttpWebRequest request = (HttpWebRequest)webRequest;
request.CookieContainer = CookieContainer;
request.Method = "PUT";
request.KeepAlive = true;
request.Timeout = Timeout.Infinite;
byte[] buffer = new byte[1024];
using (Stream stream = request.GetRequestStream())
{
using (MemoryStream memoryStream = new MemoryStream(fileBytes))
{
memoryStream.Seek(0, SeekOrigin.Begin);
for (int i = memoryStream.Read(buffer, 0, buffer.Length); i > 0;
i = memoryStream.Read(buffer, 0, buffer.Length))
{
stream.Write(buffer, 0, i);
}
}
}
WebResponse response = request.GetResponse();
response.Close();
Have you tried to change the default maximum upload file size?
What version of SharePoint are you using?

Adobe Flex 4.6 WebService request timeout

The code to get connected to my WebService (Lotus Notes Database) is created by the Flash Builder over "Data/Connect with WebService...". All works fine, but I have a problem to increase the request timeout. The API says that you can set the request timeout like this:
_serviceControl.requestTimeout = 300;
On a iOS (iPad) it seems to be work all fine. But if I run my app on desktop or on an android smartphone this only works if I set up the request timeout lower than ~30 seconds. If I don't set up the request timeout or higher than 30 and my app needs longer than 30 seconds to wait for an answer/result the "_serviceControl" fires an FaultEvent with the message:
body = ""
clientId = "DirectHTTPChannel0"
correlationId = "CDED773E-34E5-56F8-D521-4FFC393D7565"
destination = ""
extendedData = (null)
faultCode = "Server.Error.Request"
faultDetail = "Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: "http://...?OpenWebService" errorID=2032]. URL: "http://...?OpenWebService"
faultString = "HTTP request error"
headers = (Object)#1
DSStatusCode = 0
messageId = "91D11378-49D4-EDF7-CE7A-4FFCB09EBC47"
rootCause = (flash.events::IOErrorEvent)#2
bubbles = false
cancelable = false
currentTarget = (flash.net::URLLoader)#3
bytesLoaded = 0
bytesTotal = 0
data = ""
dataFormat = "text"
errorID = 2032
eventPhase = 2
target = (flash.net::URLLoader)#3
text = "Error #2032: Stream Error. URL: "http://...?OpenWebService"
type = "ioError"
timestamp = 0
timeToLive = 0
Any idea why this happens?
I had the same problem, requestTimeout didn't work.
If someone is looking for an answer, this configuration works fine for me :
import flash.net.URLRequestDefaults;
URLRequestDefaults.idleTimeout = 120000; //note this value represents milliseconds (120 secs)
Have a look here for more details : Flex HTTPService times out anyway
Though it seems to be assumed that requestTimeout doesn't work. It actually does... the 1st time.
After the 1st request, the requestTimeout is set in
HTTPService.channelSet.currentChannel.requestTimeout
If you have to change the timeout, you will want to do it there.
To see the specific offending code, see AbstractOperation.getDirectChannelSet(). Even for different instances of HTTPService, it pulls from:
private static var _directChannelSet:ChannelSet;
_directChannelSet is only instantiated once, and the requestTimeout on it is only set on creation, so even if you change the requestTimeout on HTTPService, it won't reflect in the request.

AppFabric Topic Subscription

I am trying to assemble a simple AppFabric Topic whereby messages are sent and received using the SessionId. The code does not abort, but brokeredMessage is always null. Here is the code:
// BTW, the topic already exists
var messagingFactory = MessagingFactory.Create(uri, credentials);
var topicClient = messagingFactory.CreateTopicClient(topicName);
var sender = topicClient.CreateSender();
var message = BrokeredMessage.CreateMessage("Top of the day!");
message.SessionId = "1";
sender.Send(message);
var subscription = topic.AddSubscription("1", new SubscriptionDescription { RequiresSession = true});
var mikeSubscriptionClient = messagingFactory.CreateSubscriptionClient(subscription);
var receiver = mikeSubscriptionClient.AcceptSessionReceiver("1");
BrokeredMessage brokeredMessage;
receiver.TryReceive(TimeSpan.FromMinutes(1), out brokeredMessage); // brokeredMessage always null
You have two problems in your code:
You create a subscription AFTER you send the message. You need to create a subscription before sending, because a subscription tells the topic to, in a sense, copy, the message to several different "buckets".
You are using TryReceive but are not checking for its result. It returns true, if a message was received, and false if not (e.g. Timeout has occured).
I am writing my sample application and will post it on our blog today. I will post the link here as well. But until then, move the subscription logic to before sending the message, and the receiver after it and you will start seeing results.
Update:
As promised, here is the link to my blog post on getting started with AppFabric Queues, Topics, Subscriptions.